I created a small application using Netbeans 8.1 on OSX, doing these steps:
- I created a new JForm using category "Swing GUI forms"
- I added three menus to it:
- I added a JDialog with text fields and linked it to the third menu ("TAnalyse").
In this JDialog i need copy / paste functionality for the text fields. The problem is: copy / paste only works in this dialog with "ctrl" + "c","x" or "v" and not with the osx standard "cmd" key.
I tried to add the following line of code to the constructor of the JForm but it didn't work:
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
Additional information:
I am using JDK7 and OSX Yosemite. Look and feel is "Nimbus". The two other menus ("File","Edit") aren't implemented yet.
Can you give a hint for a solution?
Update:
I created another small example with Netbeans GUI builder (Swing GUI Forms -> JDialog). I just added a menu bar to the JFrame and the a JMenuItem in the GUI builder. With the remarks from the answer below i added manually some code to the constructor:
public NewJDialogGUI(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
AbstractAction copyAction = new DefaultEditorKit.CopyAction();
copyAction.putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_C, MASK));
this.jMenuItem1.setAction(copyAction);
this.jMenuItem1.setText("Copy");
this.jMenuItem1.setMnemonic(KeyEvent.VK_C);
}
The result is:
Update2:
I created another small example with Netbeans GUI builder (Swing GUI Forms -> Application sample form).
The result is:
Finally i created an example with Netbeans (Empty Java file) with source code slightly modified from the answer below.
The result is:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…