I need modifier key state in an event that doesn't provide access to it.

E

elrod

I have a JTree with a TreeSelectionListener to load a form when the
node selection changes. I want to be able to perform a slightly
different action when the selection changes while the CTRL key is
pressed, but the TreeSelectionEvent does not provide access to the
modifier key state.
I am only necessarily interested in the modifier state if the selection
changes by a mouse click, so I could use a MouseListener for this case
if I could figure out a way to keep the TreeSelectionListener from also
loading the form for this case (I have to keep the
TreeSelectionListener method of switching forms for non-mouse-triggered
changes), since both listeners will fire for a mouse selection change.

So, in short, the ideal solution I seek is a way to know if the CTRL
key is pressed from within the TreeSelectionListener, and if that is
too impractical, then a way to keep the TreeSelectionListener from
performing a form load if the MouseListener is going to handle it.
 
E

elrod

I have a JTree with a TreeSelectionListener to load a form when the
node selection changes. I want to be able to perform a slightly
different action when the selection changes while the CTRL key is
pressed, but the TreeSelectionEvent does not provide access to the
modifier key state.
I am only necessarily interested in the modifier state if the selection
changes by a mouse click, so I could use a MouseListener for this case
if I could figure out a way to keep the TreeSelectionListener from also
loading the form for this case (I have to keep the
TreeSelectionListener method of switching forms for non-mouse-triggered
changes), since both listeners will fire for a mouse selection change.

So, in short, the ideal solution I seek is a way to know if the CTRL
key is pressed from within the TreeSelectionListener, and if that is
too impractical, then a way to keep the TreeSelectionListener from
performing a form load if the MouseListener is going to handle it.

Or, perhaps a simpler question to answer; where does a new MouseEvent
originate? When it is generated, how is its 'modifiers' field
populated? I tried to delve into the java source, but did not find an
answer. I'm guessing (but hoping I am wrong) that the event is
generated by system code, and as such, there is no accessible function
for getting the modifiers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top