The code snippet below has the problem, that it will not work, if the reload button is pressed in the browser containing the applet window. It works on the first start of the applet, but not on a reload. The same thing happens in the AppletViewer.
The reason is, that the Text.setText(...) call crashes with a NullPointerException deeply inside the HTMLParser. I already tried to place the setText call into start(), but that did not help.
Do you know any workaround? Thanks for your help. 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));
}