2012-09-01 45 views
2

我正在使用Java 7.我試圖通過使用HTML標記來格式化文本。我把文本傳入JTextField與HTML標記

JTextField text = new JTextField(); 
text.setText("<html><body><p>The program performs encryption operations on the following ciphers: </p></body></html>"); 

但是程序也打印了HTML標籤。這個文本樣本只是一個例子。 可能是什麼問題? 乾杯

+0

你確定要使用'JTextField'嗎?如果您只想顯示一些文本,[JLabel'](http://docs.oracle.com/javase/7/docs/api/javax/swing/JLabel.html)更適合。 – Jeffrey

+0

我在一些鏈接上看到HTML標籤也可以在JTextField上正常工作。它看起來像文本字段在我的應用程序看起來更好。 – uml

回答

7

JTextField確實not support HTML。你可以用JTextPane代替:

JTextPane text = new JTextPane(); 
text.setContentType("text/html"); 
text.setText("<html><body><p>The program performs encryption operations on the following ciphers: </p></body></html>");