Results 1 to 6 of 6
Thread: jTextPane doesn't show HTML
- 08-31-2010, 08:59 AM #1
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
jTextPane doesn't show HTML
Hello,
does anyone know why jTextPane1 doesn't show htmlString - after calling SetGivenContent(1)?
Java Code:package javaapplication7; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.JLabel; import java.awt.*; import java.awt.event.*; import javax.swing.Box; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.JTextPane; import java.awt.ScrollPane; import javax.swing.ScrollPaneConstants; import javax.swing.text.html.HTMLEditorKit; public class TaskFrame { JFrame jFrame1=new JFrame(); JPanel mainPanel=new JPanel(); JPanel jPanel1=new JPanel(); JPanel jPanel2=new JPanel(); JLabel jLabel1=new JLabel(); JPanel jPanel3=new JPanel(); JPanel jPanel4=new JPanel(); JPanel jPanel5=new JPanel(); JPanel jPanel6=new JPanel(); JPanel jPanel7=new JPanel(); JPanel jPanel8=new JPanel(); JPanel jPanel9=new JPanel(); JPanel jPanel10=new JPanel(); JLabel jLabel2=new JLabel(); JTextPane jTextPane1=new JTextPane(); JButton jButton1=new JButton(); JScrollPane jScrollPane1; JScrollPane jScrollPane2=new JScrollPane(jPanel4); JScrollPane jScrollPane3=new JScrollPane(jPanel9); JLabel jLabel3=new JLabel(); JLabel jLabel4=new JLabel(); JLabel jLabel5=new JLabel(); // JLabel jLabel6=new JLabel(); JLabel jLabel7=new JLabel(); JLabel jLabel8=new JLabel(); JLabel jLabel9=new JLabel(); JLabel jLabel10=new JLabel(); // public void SetGivenContent(int taskNum) { HTMLEditorKit htmlEditorKit = new HTMLEditorKit(); // jTextPane1.setContentType("text/html"); jTextPane1.setEditorKit(htmlEditorKit); String htmlString=""; if (taskNum==1) { htmlString="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n"; htmlString=htmlString+"<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1251\">\n"; htmlString=htmlString+"<style type=\"text/css\">\nPT{\nfont-size: 120%;\nfont-family: Times New Roman, Tahoma, Arial;\ncolor: #336;\n}\n"; htmlString=htmlString+"</style>\n</head>\n<body>\n<PT>blah-blah. "; htmlString=htmlString+"blah-blah.</PT>\n"; htmlString=htmlString+"</body>\n</html>\n"; } jTextPane1.setText(htmlString); } public void Init(int TaskNum){ mainPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); /////////////////////////////////////////////////////////////////////////////////////// jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.Y_AXIS)); jLabel1.setText("Given"); jTextPane1.setBackground(Color.white); SetGivenContent(1); jScrollPane1=new JScrollPane(jTextPane1); jLabel1.setAlignmentX(1); jScrollPane1.setAlignmentX(1); jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jPanel2.add(jLabel1); jPanel2.add(Box.createRigidArea(new Dimension(0,20))); jPanel2.add(jScrollPane1); /////////////////////////////////////////////////////////////////////////////////////// jPanel3.setLayout(new BoxLayout(jPanel3, BoxLayout.X_AXIS)); jLabel2.setText("Hints and explanations"); jButton1.setText("Hint"); jLabel2.setAlignmentY(0); jButton1.setAlignmentY(0); jPanel3.add(jButton1); jPanel3.add(Box.createHorizontalGlue()); jPanel3.add(jLabel2); jPanel5.setLayout(new BoxLayout(jPanel5, BoxLayout.Y_AXIS)); jPanel4.setBackground(Color.white); jPanel5.add(jPanel3); jPanel5.add(Box.createRigidArea(new Dimension(0,10))); jScrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jPanel5.add(jScrollPane2); /////////////////////////////////////////////////////////////////////////////////////// jPanel6.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); jPanel6.setLayout(new BoxLayout(jPanel6, BoxLayout.X_AXIS)); jPanel6.add(jPanel2); jPanel6.add(Box.createRigidArea(new Dimension(40,0))); jPanel6.add(jPanel5); /////////////////////////////////////////////////////////////////////////////////////// jPanel7.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); jPanel7.setLayout(new BoxLayout(jPanel7, BoxLayout.X_AXIS)); jLabel5.setText("blah"); jLabel6.setText("blah"); jLabel7.setText("blah"); jLabel8.setText("blah"); jLabel9.setText("blah"); jLabel10.setText("blah"); jPanel7.add(jLabel5); jPanel7.add(Box.createRigidArea(new Dimension(10,0))); jPanel7.add(jLabel6); jPanel7.add(Box.createRigidArea(new Dimension(10,0))); jPanel7.add(jLabel7); jPanel7.add(Box.createRigidArea(new Dimension(10,0))); jPanel7.add(jLabel8); jPanel7.add(Box.createRigidArea(new Dimension(10,0))); jPanel7.add(jLabel9); jPanel7.add(Box.createRigidArea(new Dimension(10,0))); jPanel7.add(jLabel10); /////////////////////////////////////////////////////////////////////////////////////// jPanel8.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); jPanel8.setLayout(new BoxLayout(jPanel8, BoxLayout.X_AXIS)); jLabel3.setText("Your grade: "); jLabel4.setText("Workplace"); jPanel8.add(jLabel3); jPanel8.add(Box.createHorizontalGlue()); jPanel8.add(jLabel4); /////////////////////////////////////////////////////////////////////////////////////// jPanel10.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); jPanel10.setLayout(new BoxLayout(jPanel10, BoxLayout.Y_AXIS)); jPanel9.setBackground(Color.white); jScrollPane3.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jPanel10.add(jScrollPane3); /////////////////////////////////////////////////////////////////////////////////////// mainPanel.add(jPanel6); mainPanel.add(Box.createRigidArea(new Dimension(0,10))); mainPanel.add(jPanel7); mainPanel.add(Box.createRigidArea(new Dimension(0,10))); mainPanel.add(jPanel8); mainPanel.add(Box.createRigidArea(new Dimension(0,10))); mainPanel.add(jPanel10); jFrame1.setSize(1024, 760); mainPanel.setSize(1024, 760); jFrame1.add(mainPanel); jFrame1.setVisible(true); } }
- 08-31-2010, 01:19 PM #2
did you call the setContextType("text/html") to tell JTextPane that you are giving it HTML
Michael P. O'Connor
http://www.mikeoconnor.net
- 08-31-2010, 01:24 PM #3
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
Yes, I tried to call it and there was no effect, so I commented that line and tried to use HTMLEditorKit.
- 08-31-2010, 01:51 PM #4
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
There is something in htmlString that the compiler doesn't like;
if I use htmlString="<html>Hallo world!</html>", then jTextPane1 shows that text.
- 08-31-2010, 02:23 PM #5
Michael P. O'Connor
http://www.mikeoconnor.net
- 08-31-2010, 02:29 PM #6
Member
- Join Date
- Aug 2010
- Posts
- 14
- Rep Power
- 0
Similar Threads
-
how to show web browser in mobile app or is it possible to show it in textArea
By Basit781 in forum CLDC and MIDPReplies: 3Last Post: 05-27-2010, 10:54 AM -
LineNumber JTextPane html Content
By mcjava in forum AWT / SwingReplies: 3Last Post: 08-31-2009, 02:38 AM -
How can I include a html file in html textarea?
By surya_dks in forum New To JavaReplies: 2Last Post: 10-04-2008, 07:20 AM -
netbeans 6.0 not show commpunent or show blank page
By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 06:20 AM -
how to show a html document on JTextPane
By mary in forum Advanced JavaReplies: 2Last Post: 08-02-2007, 01:40 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks