skirsch00
skirsch00

Reputation: 29

JLabel not showing up

For some reason my JLabel isn't displaying and I can't figure out why (editString DOES have a value).

compFrame.removeAll();
JPanel editPane = new JPanel();
editPane.setLayout(new GridLayout(0,1));
compFrame.add(editPane);
//JLabel lastValue = new JLabel(editString);
editPane.add(new JLabel(editString));

compFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
compFrame.setVisible(true);

Upvotes: 1

Views: 46

Answers (1)

Shahid
Shahid

Reputation: 481

you should use removeAll on ContentPane. Try this

compFrame.getContentPane().removeAll();

The API doc for removeAll says:

This method changes layout-related information, and therefore, invalidates the component hierarchy. If the container has already been displayed, the hierarchy must be validated thereafter in order to reflect the changes.

Upvotes: 1

Related Questions