I'm having some problems when trying to set a panel within my JFrame to visible when someone either presses enter or clicks the JButton within my two methods shown in previous post.
I am getting the following error:
Cannot make a static reference to the non-static field Interface.panel.
The code for my the TextHandler method which uses an ActionListener when a user presses enter on the text field is as follows:
private class TextHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {
Interface.panel.setVisible(true); //(where Interface is the method with my GUI components in)
disp = "Searching: " + e.getActionCommand() + "\t...";
jtfUneditableText.setText(disp);
}
}
When i just use
panel.setVisible(true);
it does compile, but comes up with a bunch of errors when i press enter and try to show the panel, probably due to it not recognising panel in the TextHandler method as it is in Interface().
the code for my JPanel panel is within my class Interface() along with all the other code for creating the GUI textfields and such.
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS));
b = new JLabel("Blah blah");
c = new JLabel("blah blah");
panel.add(b);
panel.add(c);
panel.setVisible(false);
what am i doing wrong?