1
下面的代码片断有问题,如果在包含小程序窗口的浏览器中按下重新加载按钮,它将无法正常工作。它适用于小程序的第一次启动,但不在重新加载。 AppletViewer中也会发生同样的事情。奇怪的HTMLEditorKit问题
原因是,Text.setText(...)调用在HTMLParser内深深地陷入了NullPointerException。我已经尝试将setText调用放入start(),但这没有帮助。
您是否知道任何解决方法?谢谢你的帮助。 RG
@Override
public void init()
{
//Execute a job on the event-dispatching thread:
//creating this applet's GUI.
try
{
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
}
catch (Exception e)
{
e.printStackTrace();
System.err.println("createGUI didn't successfully complete");
}
}
private void createGUI()
{
((JComponent)this.getContentPane()).setBorder(new CompoundBorder
(BorderFactory.createRaisedBevelBorder(),
new EmptyBorder(5,5,5,5)));
BorderLayout bl=new BorderLayout();
bl.setVgap(5);
setLayout(bl);
Input=new JTextField();
Input.setFont(new Font("arial",Font.PLAIN,14));
add("North",Input);
Input.addActionListener(this);
HTMLEditorKit kit=new HTMLEditorKit();
Text=new JTextPane();
Text.setFont(new Font("arial",Font.PLAIN,14));
Text.setEditorKit(kit);
Text.setText("<p>Test</p>");
Text.setEditable(false);
Text.setBackground(Color.white);
add("Center",new JScrollPane(Text));
}
感谢您的回答!是的布局代码是老式的,但它仍然有效,这不是问题。我尝试了没有HTMLEditorKit的JEditorPane方法,这似乎是相同的,但更容易。但是,applet在重新加载后仍然崩溃,在HTML解析器中遇到同样的问题。如果我使用普通文本,我可以随时重新加载,只要我喜欢。 – Rene 2010-11-08 20:42:23
不,缺少html和body标签没有任何区别。 – Rene 2010-11-08 20:43:10
感谢您的帮助,我发现它是:这是一个bug请参阅http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6993691 – Rene 2010-11-08 20:44:17