I've got a component with several JTables on it. I've installed custom TransferHandlers on the tables. Now, I wan开发者_高级运维t a means to invoke the cut/copy/paste commands on these tables, via:
- The menubar, which works on the currently focused JTable
- Popup menu on the JTables
- Keyboard shortcut, which works on the currently focused JTable
JTable's actionMap already has entries for "cut", "copy", "paste". The actions for these keys do the correct thing, invoking the TransferHandler.
I've tried the following:
dataTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(cutMenuItem.getAccelerator(), "cut");
This works when I press cmd-X, but not when I select "cut" from the menu. I assume this is because the menu consumes the event, and it never gets to the JTable.
I can think of several hacky ways to implement this, but is there a clean way to go about it? How can I get my menu items to send their actionCommand
to the currently focused component?
It's not clear how you are initializing the menu items. As JTable
is not one of the text components, you may want to look at CCP in a non-Text Component with regard to setting up the Edit
menu.
精彩评论