aquasw
asked on
JTree MouseListener problem
Hi,
I have a tree with nodes that contains a label and a checkbox.
I would like to behave differently if the checkbox is clicked or if the click is in different location in the node.
It all should be in context of the mouse listener implementation:
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
...
}
is there a way of instructing JTree to display both checkbox and text but distinguish the pressing to one of them?
or is there an easier way?
Thanks.
I have a tree with nodes that contains a label and a checkbox.
I would like to behave differently if the checkbox is clicked or if the click is in different location in the node.
It all should be in context of the mouse listener implementation:
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
...
}
is there a way of instructing JTree to display both checkbox and text but distinguish the pressing to one of them?
or is there an easier way?
Thanks.
Add JPanel as ur tree node, and then add checkbox and JLabale to that each panel. then separately u can trace the click action.
ASKER
I thought of that.
I added my implementation of Jpanel and added a checkbox and label.
I tried to add a mouselistener at the constructing process to each but the pressing isn't getting to the listener.
I added my implementation of Jpanel and added a checkbox and label.
I tried to add a mouselistener at the constructing process to each but the pressing isn't getting to the listener.
you need to add your listener to the jtree and then determine from the coords of the click what was clicked.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I know I can get the coordinates and check the bounds using a rectangle or any other....
I think it's a bit of avoiding the actual problem.
I don't want to manually calculate the area of the clicked item.
isn't there a way of adding a listener to the checkbox separately or the label?
I think it's a bit of avoiding the actual problem.
I don't want to manually calculate the area of the clicked item.
isn't there a way of adding a listener to the checkbox separately or the label?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Exactly
thanx 4 axxepting