Computer Science Canada

HTML Text Alignment Issues

Author:  randint [ 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.

Author:  Tony [ 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.


: