Popup menu problem.

Hi.

I want to make a popup menu which will be showing me chortcuts (copy, paste,cut, delete) and if I press them will change my JTable:

Popup menu works but I don't know why shortcuts doesn't.

Here is some code:

publicvoid createPopupMenu(JTable table){

JMenuItem menuItem;

JPopupMenu popup =new JPopupMenu();

menuItem =new JMenuItem("Copy CTRL+C");

menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));

//menuItem.setActionCommand("copy");

menuItem.addActionListener(this);

popup.add(menuItem);

menuItem =new JMenuItem("Paste CTRL+V");

menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,KeyEvent.CTRL_DOWN_MASK));

//menuItem.setActionCommand("paste");

menuItem.addActionListener(this);

popup.add(menuItem);

menuItem =new JMenuItem("Delete");

menuItem.setAccelerator(KeyStroke.getKeyStroke("DELETE"));

//menuItem.setActionCommand("kasuj");

menuItem.addActionListener(this);

popup.add(menuItem);

MouseListener popupListener =new PopupListener(popup);

table.addMouseListener(popupListener);

}

I use Java Excel Adapter to copy from excel sheet. I works fine but in my shortcuts in popup menu doesn't.

http://www.physionet.org/physiotools/puka/sourceCode/subjectData/ExcelAdapter.java

to use shortcuts from ExcelAdapter i write:

ExcelAdapter myAd =new ExcelAdapter(table);

calcColumnWidths sze =new calcColumnWidths(table);

Those shortcuts works fine in Jtable but doesn't i popupmenu.

[2264 byte] By [Lukasz_1981a] at [2007-11-26 21:18:10]
# 1

When focus is on the table then the actions defined by the table for Ctrl+C, Ctrl+V are executed.

When you use a popup menu you can't just invoke Ctrl+C and expect it to invoke the table copy action. You need to write a custom Action that invokes the copy action from the table

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.

.

camickra at 2007-7-10 2:56:56 > top of Java-index,Desktop,Core GUI APIs...