Hi can someone please help and tell me why I get a NPE when I append to the JTextArea.
The example in the thread above runs fine on my PC but my code below doesn't work and I can't spot any differences!!
Thanks
Ian
package JavaDev.TestGUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Window extends JFrame{
private final static String newLine = "\n";
private JTextArea log;
private Component createLogger(){
JPanel pane = new JPanel(new GridLayout(0, 1));
log = new JTextArea("Hola");
log.setEditable(false);
log.setLineWrap(true);
log.setWrapStyleWord(true);
JScrollPane scrollPane =
new JScrollPane(log,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
pane.add(log);
pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
10, //bottom
30) //right
);
pane.setPreferredSize(new Dimension(600, 600));
return pane;
}
public void writeToLog(String text){
log.setText(text + newLine);
//log.setCaretPosition(log.getDocument().getLength());
}
private Component createButtons(){
JPanel pane = new JPanel();
JButton cancelButton = new JButton("Cancel");
JButton buildButton = new JButton("Start Build..");
pane.add(cancelButton);
pane.add(buildButton);
/*pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
30, //bottom
30) //right
);*/
return pane;
}
private Component createFileChooser(){
JPanel pane = new JPanel(new GridLayout(0, 1));
JTextField field = new JTextField("Build Locaton: " + System.getProperty("user.home"));
field.setEditable(false);
JButton editButton = new JButton("Edit Build Location..");
pane.add(field);
pane.add(editButton);
/*pane.setBorder(BorderFactory.createEmptyBorder(
30, //top
30, //left
30, //bottom
30) //right
);*/
return pane;
}
private void createAndShowGUI(){
//Make sure we have nice windows decorations
JFrame.setDefaultLookAndFeelDecorated(true);
//WindowUtilities.setNativeLookAndFeel();
//Create and set up the window.
JFrame frame = new JFrame("MarketAxess Release Automation");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Window win = new Window();
Component contents = win.createLogger();
frame.getContentPane().add(contents, BorderLayout.CENTER);
frame.add(createFileChooser(),BorderLayout.PAGE_START);
frame.add(createButtons(), BorderLayout.PAGE_END);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public void launch() {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
[ July 16, 2006: Message edited by: Ian Hamilton ]