Posted: 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.*; publicclass Trial extendsJFrame { privateJPanel p = newJPanel();
privateJLabel l = newJLabel("");
public Trial () { String line = null, text = "";
try { BufferedReader br = newBufferedReader(newFileReader("0.html"));
while((line = br.readLine()) != null) {
text += line;
}
br.close();
setDefaultCloseOperation (3);
l = newJLabel(text);
p.add(l);
setContentPane (p);
setSize (Toolkit.getDefaultToolkit().getScreenSize());
setResizable (false);
setVisible (true);
} catch(Throwable t) {
t.printStackTrace();
} }
publicstaticvoid main (String args[]) { new Trial ();
} }
Here is the "0.html" file
HTML:
<html> <h1><fontface = "Arial Black"size = 25color = "black">Sample Title</font></h1> <body> <fontface = "Times New Roman"size = 12color = "black"> <palign="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
Tony
Posted: 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.