Reputation: 1138
Just how you add JLabels, JTextFields, JButtons by doing this add(label1); add(button1);
how to remove?
I have a button that will remove a particular JTextField.
The button:
thehandler3 handler3 = new thehandler3();
button3.addActionListener(handler3); // first x button
private class thehandler3 implements ActionListener{
public void actionPerformed(ActionEvent event){
remove(field1);
}}
It is not working. I get no compliation or execution error.
Upvotes: 1
Views: 6139
Reputation: 8884
You need to call remove() on the container you want to remove the component from, like this:
panel.remove(label1);
You will also want to consider threading issues when updating the UI:
Upvotes: 4
Reputation: 324118
The code would be:
panel.remove(...);
panel.revalidate();
panel.repaint(); // sometimes needed
You need to remove the component and then tell the panel to layout the remaining components.
Upvotes: 4