Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 HTML Text Alignment Issues
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
randint




PostPosted: Sat Mar 23, 2013 9:42 am   Post subject: HTML Text Alignment Issues

Right now, I am designing a Swing application. I added a JPanel to a JFrame, a JLabel to that JPanel mentioned above. I was attempting to take advantage of the JLabel HTML parser's capabilities, as my application needs to display mathematical content that have special symbols, superscripts, etc...I assumed that JLabel is completely compatible with HTML, but, when I display the content in the JPanel, it does not work, all text is aligned center:
So, here is the test program:
Java:

import java.io.*;
import java.awt.*;
import javax.swing.*;
public class Trial extends JFrame
{
    private JPanel p = new JPanel ();
    private JLabel l = new JLabel ("");
    public Trial ()
    {
        String line = null, text = "";
        try
        {
            BufferedReader br = new BufferedReader (new FileReader ("0.html"));
            while ((line = br.readLine ()) != null)
            {
                text += line;
            }
            br.close ();
            setDefaultCloseOperation (3);
            l = new JLabel (text);
            p.add (l);
            setContentPane (p);
            setSize (Toolkit.getDefaultToolkit ().getScreenSize ());
            setResizable (false);
            setVisible (true);
        }
        catch (Throwable t)
        {
            t.printStackTrace ();
        }
    }


    public static void main (String args[])
    {
        new Trial ();
    }
}

Here is the "0.html" file
HTML:

<html>
<h1><font face = "Arial Black" size = 25 color = "black">Sample Title</font></h1>
<body>
<font face = "Times New Roman" size = 12 color = "black">
<p align="left">Insert some sample text here.</p>
</font>
</body>
</html>

Any suggestions? I do not know how JLabel parses the HTML that is being inputted.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Mar 23, 2013 11:48 pm   Post subject: Re: HTML Text Alignment Issues

randint @ Sat Mar 23, 2013 9:42 am wrote:
Any suggestions? I do not know how JLabel parses the HTML that is being inputted.

I think just this means that you need to look up documentation on how JLabel works.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: