如何删除 JLabel? [英] How to remove JLabels?
本文介绍了如何删除 JLabel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就是如何通过执行 add(label1) 来添加 JLabels、JTextFields、JButtons;添加(按钮 1);
Just how you add JLabels, JTextFields, JButtons by doing this add(label1); add(button1);
如何删除?
我有一个按钮可以删除特定的 JTextField.
I have a button that will remove a particular JTextField.
按钮:
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.
推荐答案
代码如下:
panel.remove(...);
panel.revalidate();
panel.repaint(); // sometimes needed
您需要移除组件,然后告诉面板布局剩余的组件.
You need to remove the component and then tell the panel to layout the remaining components.
这篇关于如何删除 JLabel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文