
-----------------------------------
randint
Sat Mar 23, 2013 9:42 am

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:

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
Here is the "0.html" file


Sample Title


Insert some sample text here.




Any suggestions? I do not know how JLabel parses the HTML that is being inputted.

-----------------------------------
Tony
Sat Mar 23, 2013 11:48 pm

Re: HTML Text Alignment Issues
-----------------------------------
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.
