您好,我有一个标签,我已为其设置了图标,我想在单击按钮后删除此图标,它的方法是什么?
// Create icon
Icon icon = new ImageIcon(getClass().getResource("/foo/bar/baz.png"));
// Create label
final JLabel lbl = new JLabel("Hello, World", icon, JLabel.LEFT_ALIGNMENT);
// Create button
JButton btn = new JButton("Click Me");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// Remove icon when button is clicked.
lbl.setIcon(null);
// **IMPORTANT** to call revalidate() to cause JLabel to resize and be repainted.
lbl.revalidate();
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)