Using popup menus with cells in a JTable

  • Thread starter vesperdem+c.l.j.programmer
  • Start date
V

vesperdem+c.l.j.programmer

I have seen discussions about this already here. However, I haven't
seen any mention of how to deal get a popup to work on a cell that is
in edit mode.

I have a project where I have been asked to keep the table in "edit
mode" all the time. Thanks to the newsgroups, I was able to get that to
work just fine.

What I hadn't realized was that the right-click popups that were in the
table now don't work. They expect the table to be in "cursor mode".

Now, depending on where the user right-clicks, the old listeners can
handle the message. However, if the user tries to right-click on the
cell they are currently editing, nothing happens. This is, of course,
because the table's cell editor is currently focused and not the table.
So a right-click message goes to the component that is used by the cell
editor.

What I need is for that cell editor to treat the right-click like the
rest of the table.

The popup menu has options to add a row to the table, or change the
value of the cell to a specific value based on external data.

Am I barking up a dead tree here? Is this even remotely possible? I've
done some experiments, but nothing that was really useful.
Thanks for your attention!
 
C

Chris Smith

Now, depending on where the user right-clicks, the old listeners can
handle the message. However, if the user tries to right-click on the
cell they are currently editing, nothing happens. This is, of course,
because the table's cell editor is currently focused and not the table.
So a right-click message goes to the component that is used by the cell
editor.

What I need is for that cell editor to treat the right-click like the
rest of the table.

Add the listener to the cell editor component when you create that
component. Remove the listener when you destroy that component, and
then add it to the next one. One nice thing about listeners is that
they aren't tied to any particular GUI component.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
V

vesperdem+c.l.j.programmer

Thanks a bunch! I'm not sure if I have the addListener in the correct
place, but I get the popup menu when the right-click happens. That is
certainly a move in the right direction.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top