Hello everyone!
I'm stuck with a problem, caused by a mix of listeners in a JTree.
Here goes:
I created my own renderer for the tree, that is one JLabel (icon+name), and then another JLabel (let's name it button) that has a small icon. I want the user to be able to click on the "button" JLabel and something to happen.
e.g.
Program1 (on)
Program2 (on)
assuming (on) is an icon. When the user presses (on) i want the icon to turn into (off) and turn off Program1.
as shown in this image:
[IMGnothumb]http://img859.imagesha ck.us/img859/669/captureh.png[/IMGnothumb]
Here is the code:
However, when I click on the "button" nothing happens. Does anyone have any idea?
Thanks in advance!
Alex
I'm stuck with a problem, caused by a mix of listeners in a JTree.
Here goes:
I created my own renderer for the tree, that is one JLabel (icon+name), and then another JLabel (let's name it button) that has a small icon. I want the user to be able to click on the "button" JLabel and something to happen.
e.g.
Program1 (on)
Program2 (on)
assuming (on) is an icon. When the user presses (on) i want the icon to turn into (off) and turn off Program1.
as shown in this image:
[IMGnothumb]http://img859.imagesha ck.us/img859/669/captureh.png[/IMGnothumb]
Here is the code:
Code:
public TreeRenderer() {
renderer = new JPanel(new GridLayout(0, 1));
renderer.setLayout(new BoxLayout(renderer, BoxLayout.X_AXIS));
titleLabel = new JLabel(" ");
titleLabel.setForeground(Color.black);
renderer.add(titleLabel);
buttonLabel = new JLabel(" ");
buttonLabel.addMouseListener(new java.awt.event.MouseAdapter() {
private boolean on;
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("shalal");
System.out.println(" clicked ");
on=true;
icon = createImageIcon("http://bytes.com/images/jtree red.jpg","");
buttonLabel.setIcon(icon);
}
@Override
public void mouseEntered(java.awt.event.MouseEvent evt) {
System.out.println("sda");
}
@Override
public void mouseExited(java.awt.event.MouseEvent evt) {
System.out.println("14");
}
});
renderer.add(buttonLabel);
Thanks in advance!
Alex