Results 1 to 3 of 3
Thread: Swing VK_X and VK_C Issue
- 04-11-2012, 09:40 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Swing VK_X and VK_C Issue
I have an issue where for some reason the VK_X and VK_C KeyEvents do not work at all, I can change them to anything else and it works, I've tried this on two other PCs as well... It just acts like Ctrl-C and X are in use or something, the combination is displayed in the menu so I imagine I typed it in right. This is my code
Java Code:import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ExProject implements ActionListener { JLabel selectedItem; JTextArea textContents; ExProject() { JFrame jfrm = new JFrame("Experimental GUI"); jfrm.setSize(215, 350); jfrm.setLocation(350, 350); jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /*** Start Menus ***/ JMenuBar jmb = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu editMenu = new JMenu("Edit"); JMenuItem newFile = new JMenuItem("New"); JMenuItem openFile = new JMenuItem("Open"); JMenuItem exitProg = new JMenuItem("Exit"); newFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK)); openFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); exitProg.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK)); newFile.addActionListener(this); openFile.addActionListener(this); exitProg.addActionListener(this); fileMenu.add(newFile); fileMenu.add(openFile); fileMenu.addSeparator(); fileMenu.add(exitProg); JMenuItem cutFrom = new JMenuItem("Cut"); JMenuItem copyFrom = new JMenuItem("Copy"); JMenuItem pasteTo = new JMenuItem("Paste"); cutFrom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); /***** PROBLEM LINE!!! *****/ copyFrom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); /***** PROBLEM LINE!!! *****/ pasteTo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK)); cutFrom.addActionListener(this); copyFrom.addActionListener(this); pasteTo.addActionListener(this); editMenu.add(cutFrom); editMenu.add(copyFrom); editMenu.add(pasteTo); jmb.add(fileMenu); jmb.add(editMenu); /*** End Menus ***/ /*** Start Main Contents ***/ selectedItem = new JLabel("Selected Items Log"); jfrm.add(selectedItem, BorderLayout.NORTH); textContents = new JTextArea(); textContents.setEditable(false); JScrollPane windowContents = new JScrollPane(textContents); jfrm.add(windowContents, BorderLayout.CENTER); /*** End Main Contents ***/ jfrm.setJMenuBar(jmb); jfrm.setVisible(true); } public void actionPerformed(ActionEvent ae) { String cmd = ae.getActionCommand(); String contents = textContents.getText(); if (cmd.equals("Exit")) { System.exit(0); } else { textContents.setText(contents + "Selected Item - " + cmd + "\n"); } } public static void main(String args[]) { new ExProject(); } }
I've tried changing the keys to other ones and it works, also keeping the KeyEvent but changing the InputEvent to ALT_MASK works as well, all other accelerators work in this code, am I just missing something?
- 04-11-2012, 09:46 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,605
- Rep Power
- 5
Re: Swing VK_X and VK_C Issue
Are those events are being captured/consumed by a Text component, for instance the JTextArea? They have by default their own action map and accelerators for copy/cut/paste.
- 04-11-2012, 09:59 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Drawing issue with Applet/Swing
By The_Capn in forum Java AppletsReplies: 2Last Post: 06-18-2011, 05:30 AM -
AWT/Swing Mixing Still and issue on MAC OSX?
By Confused in forum AWT / SwingReplies: 2Last Post: 02-21-2010, 08:34 PM -
Swing Timers Issue.
By killpoppop in forum AWT / SwingReplies: 4Last Post: 03-09-2009, 11:17 PM -
[SOLVED] Swing Timer issue
By Doctor Cactus in forum New To JavaReplies: 6Last Post: 03-03-2009, 12:25 PM -
Java1.5 Swing Issue
By naveenbk in forum AWT / SwingReplies: 1Last Post: 11-23-2008, 08:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks