Re: JTree with checkboxes and mouse click
From: Steve W. Jackson (stevewjackson_at_charter.net)
Date: 04/22/04
- Next message: dianap_at_vf.shawcable.net: "My lesbian fetish pics"
- Previous message: loquak: "Complete repaint of everything"
- In reply to: Grzegorz Drozdz: "JTree with checkboxes and mouse click"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 22 Apr 2004 13:58:12 -0500
In article <c66jnf$hen$1@inews.gazeta.pl>,
Grzegorz Drozdz <lynx@reja.osiedla.net> wrote:
>:Hi,
>:
>:I have JTree, each node contains JCheckBox and JLabel,
>:of course I've created class that implements TreeCellRenderer.
>:
>:I store my data in class that implements TreeModel.
>:
>:How can I check which component was clicked by user?
>:
>:I add MouseListener and this fragment:
>:
>:TreePath treePath = tree.getPathForLocation(e.getX(), e.getY());
>:..
>:Object c = treePath.getLastPathComponent();
>:
>:(e is MouseEvent of course)
>:
>:c is the object stored in my TreeModel.
>:
>:But how can I check if user clicked checkbox, label or icon in JTree?
>:TreePath shows me only which node it was...
>:
>:Thanks
>:
>:Lynx
I don't use those particular kinds of components in my tree, so I don't
have a tried solution for you. But I can suggest possibilities.
It seems to me that the easier approach would simply be to put your
MouseListener on the actual component if you want to know when the
JLabel was clicked. JLabel supports the addMouseListener call, and can
then respond automatically when clicked on (ignoring the enter and exit
methods). As for the JCheckBox, it too inherits from Component and thus
supports the MouseListener. But it's also able to have an
ActionListener that will respond when clicked so that you can track its
state. In either case, you're able to get the source from the
MouseEvent if you use a shared listener.
= Steve =
-- Steve W. Jackson Montgomery, Alabama
- Next message: dianap_at_vf.shawcable.net: "My lesbian fetish pics"
- Previous message: loquak: "Complete repaint of everything"
- In reply to: Grzegorz Drozdz: "JTree with checkboxes and mouse click"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|