hi i have a label that i have set a icon for it, i want to remove this icon after clicking on a button, what is the method for it?
This should be a comment, not an answer.
Oded
2010-02-10 09:16:13
Agreed. I was unsure where to put the comment. Thanks.
Padmarag
2010-02-10 09:18:19
+1
A:
label.setIcon(null)
in the event handler that handles the button click, if you're using Swing.
ndn
2010-02-10 09:15:47
+1 for actually posting what comes to mind when reading the question.
Frederik Wordenskjold
2010-02-10 09:26:29
+1
A:
// 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();
}
});
Adamski
2010-02-10 09:43:32