Cannot override Ctrl + C in JDialog

Hey guys I cannot override the Ctrl+C function in JDialog for some reason. I can get other combos to work (Ctrl + O) but no cigar with C.
Below is the code I'm using, Im wondering if anyone has any suggestions?
Thanks
          KeyStroke ctrlCKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK, false);          
          Action closeWindow = new AbstractAction()
               public void actionPerformed(ActionEvent e)
                    System.out.println("hello");
                    setVisible(false);
          _mainPanel.getInputMap().put(ctrlCKeyStroke, "none");
          _mainPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
          .put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK), "CTRLC");

I am no expert in this, but I think that you have to bind the InputMap for the JTextField's Ctrl-C to a null action. This unbinds the keystroke from this component. And then you have to bind it correctly for the containing control, here mainPanel. Something like so perhaps:
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
public class OverrideCtrlC
  private static final String CTRL_C_KEYSTROKE = "Control-C";
  private JPanel mainPanel = new JPanel();
  private JTextField textField = new JTextField(12);
  public OverrideCtrlC()
    mainPanel.add(textField);
    mainPanel.setPreferredSize(new Dimension(300, 200));
    setKeyBindings();
  private void setKeyBindings()
    int inputMapArg = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
    InputMap inputmap = mainPanel.getInputMap(inputMapArg);
    KeyStroke ctrlCStroke = KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK);
    inputmap.put(ctrlCStroke, CTRL_C_KEYSTROKE);
    mainPanel.getActionMap().put(CTRL_C_KEYSTROKE, new CtrlCAction());
    inputmap = textField.getInputMap();
    inputmap.put(ctrlCStroke, "null"); // I don't map this to an action
  private class CtrlCAction extends AbstractAction
    public void actionPerformed(ActionEvent arg0)
      JOptionPane.showMessageDialog(mainPanel, "Control C has been pushed",
          "Ctrl-C Action", JOptionPane.INFORMATION_MESSAGE);
  public JPanel getPanel()
    return mainPanel;
  private static void createAndShowGUI()
    JFrame frame = new JFrame("OverrideCtrlC Application");
    frame.getContentPane().add(new OverrideCtrlC().getPanel());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  public static void main(String[] args)
    EventQueue.invokeLater(new Runnable()
      public void run()
        createAndShowGUI();
}Edited by: Encephalopathic on Jul 2, 2008 3:39 PM

Similar Messages

  • Hi. After I have loaded a picture into Photoshop some of the menu tools are greyed out and I cannot use the keyboard short cut, for instance I cannot use Ctrl   T to enter free transform mode. Also the toolbar is so small I cannot see the icons without ge

    Hi. After loading a picture into Photoshop some of the menu tools are greyed out and I cannot use the keyboard short cuts, for instance I cannot use Ctrl + T for free transform, how do I resolve this problem. In addition the tool Icons are so small I have to get close to the screen to see them, is there anyway the Icons can be made bigger without reducing the resolution of the screen.
    Thanks
    Derek

    Are you working on a background layer? If so, Ctrl + T will not work. Press Alt and double-click your background layer to convert to a normal layer (or right-click BG layer and select Layer from Background) and try again.
    If you're working in Photoshop CC 2014 you can go to Preferences > Experimental Features and tick "Scale UI 200% for high-density displays" to make your buttons and icons larger.

  • CANNOT OVERRIDE DOCUMENT ROUTING ID FOR SPECIFIC TRADING PARTNER FOR ROSETT

    Cannot override Document Routing ID for specific trading partner for RosettaNet transactions.
    The Document Routing ID for other transactions types (e.g EDI) can be overridden when creating operation capability for a trading partner by unchecking "Use Existing Document Proto Parameter Values" and "Use Default Document Definition".
    This does not work for RosettaNet transactions as no option to override the values is available when "Use Default Document Definition" is unchecked.

    Hello,
    I have replicated this issue and it appears to be a bug. I shall follow up regarding the same.
    Rgds,Ramesh

  • Since upgrading to LION unable to connect to wifi, in system preferences it says wifi off - cannot override it, what should i do?

    since upgrading to LION unable to connect to wifi, in system preferences it says wifi off - cannot override it, what should i do?

    While we all have MacBooks in this forum most of us don’t run Mountain Lion. There's a Mountain Lion Support Community where everybody has Mountain Lion. You should also post this question there to increase your chances of getting an answer. https://discussions.apple.com/community/mac_os/os_x_mountain_lion

  • Cannot override "codebase" with javaws -codebase argument with java 1.7.0_40

    I have a jnlp application. The online installation is working perfectly.
    But when I try to install it from cd or hard disc, it is not working. The -codebase parameter will be ignored.
    I am offline and java always tries to download the source files from the "codebase" of the .jnlp file ignoring the override parameter.
    When I try the "javaws -codebase file:///c://test -import c:\test\test.jnlp" I get an error "application cannot be installed" and a detailed information "unable to download the application from location http:...".
    I am using the java 1.7.0_40 32 bit version.
    None of the described solutions in the following links are working:
    https://today.java.net/pub/a/today/2008/07/10/distributing-web-start-via-cd-rom.html
    How to use the Java Web Start CD-Install feature ?
    i have searched the web but I couldnt find a solution or a confirmation that this is a bug. I searched the bug data bank too, but I couldnt find anything.
    Any help will be much appreciated. Actually I just want to do a very simple thing.
    If I am online while performing the import with the -codebase override argument then java download the application from the original .jnlp "codebase" web adress.
    HINT: With a windows 64 bit and java 64 bit the import works offline and the override works too.

    Have you examined the jnlp download servlet implementation? Whenever I have issues like this, I connect my eclipse to the server and step through the jnlp download servlet code to see what is going on. Usually its my mistake.

  • How to override Ctrl-Click behavior in Java L&F

    On the Mac, Ctrl-Click is the popup trigger. While Java L&F designers were obviously aware of this (it is warned about in the Java Look and Feel Design Guidelines, 2nd ed, page 106). However, just two pages later (page 108), they then generically specifify that Ctrl-Click is used in lists and tables to toggle the selection.
    The implementation of the Java L&F does not appear to consider the Mac's use of Ctrl-Click and still toggles selection. If there is an additional mouse listener that shows a menu in response to the popup trigger, it will ALSO open the menu on Ctrl-Click.
    What is the best way to overide the Ctrl-Click behavior in JTable etc. to NOT do the toggle selection? Note that this is a mouse event and not a key event, so it can't be turned off or changed by the getActionMap() mechanism.
    Also, does anyone know what the "Command" modifier on the Mac (Command-Click is supposed to toggle selection on Macs) shows up as in the InputEvent (isMetaDown(), isAltGraphDown()...)?

    Try extending the JList and override the processMouseEvent(MouseEvent evt) method and show your popup menu when the user clicks the mouse while holding the CTRL key down. The code below demonstrates the same.
    import java.awt.BorderLayout;
    import java.awt.event.MouseEvent;
    import java.util.Vector;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JOptionPane;
    import javax.swing.JScrollPane;
    import javax.swing.ListModel;
    import javax.swing.WindowConstants;
    public class Temp extends JFrame {
         public Temp() {
              super("Temp");
              setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              String [] items = {"One", "Two", "Three", "Four", "Five"};
              JList list = new MyList(items);
              JScrollPane scroller = new JScrollPane(list);
              getContentPane().add(scroller, BorderLayout.CENTER);
              pack();
              setVisible(true);
         class MyList extends JList {
              public MyList() {
                   super();
              public MyList(Object[] listData) {
                   super(listData);
              public MyList(Vector listData) {
                   super(listData);
              public MyList(ListModel dataModel) {
                   super(dataModel);
              protected void processMouseEvent(MouseEvent evt) {
                   System.out.println(evt.isPopupTrigger());
                   int onmask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
                   if(evt.getModifiersEx() == onmask) {
                        JOptionPane.showMessageDialog(this, "Control + click");
                   else {
                        super.processMouseEvent(evt);
         public static void main(String[] args) {
              new Temp();
    }Hope this helps
    Sai Pullabhotla

  • Overriding Ctrl+Tab

    I try to override the Ctrl-Tab key combination using the following:
            final KeyStroke focusUnderneathTableKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, Event.CTRL_MASK);
            wrapper.overrideShortcutKey(new FocusOnTableAction(false), focusUnderneathTableKeyStroke, "focusUnderneathTable");The method overrideShortcutKey() is:
        public void overrideShortcutKey( AbstractAction action, KeyStroke keyStroke, String sName )
            InputMap im = getComponent().getInputMap( JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT );
            ActionMap am = getComponent().getActionMap();
            im.put( keyStroke, sName );
            am.put( sName, action );
        }This does not seem to work. If, however, I replace the Tab key with 'Q', it works. I want this to transfer focus to a wrapper underneath a table.
    Anybody any suggestions for this? And why does Ctrl+Tab not work whereas Ctrl+Q works?

    I'm assuming by normal tab, you want to insert a tab. So here's this:
    import java.awt.*;
    import java.util.HashSet;
    import java.util.Set;
    import javax.swing.*;
    public class TextAreaTab {
         public static void main( final String[] args ) {
              Runnable doCreate = new Runnable() {
                   public void run() {
                        new TextAreaTab().createGUI();
              SwingUtilities.invokeLater( doCreate );
         private void createGUI() {
              JButton button = new JButton( "Button" );
              JTextArea textArea = new JTextArea();
              textArea.setText( "TextArea" );
              KeyStroke ctrlTab = KeyStroke.getKeyStroke("ctrl TAB" );
              Set set = new HashSet( textArea.getFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS) );
              set.remove( ctrlTab );
              textArea.setFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, set );
              textArea.getInputMap().put( ctrlTab , "insert-tab" );
              JFrame frame = new JFrame( "TextAreaTab" );
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.getContentPane().setLayout( new BorderLayout() );
              frame.getContentPane().add( button, BorderLayout.SOUTH );
              frame.getContentPane().add( textArea, BorderLayout.CENTER );
              frame.setSize( new Dimension( 250, 100 ) );
              frame.show();
    }

  • Cannot Send Ctrl+B command over serial Com2

    I am trying to communicate with a serial instrument. The ascii command is "STX" however with labview when
    the command is sent there is no response. Using Hyperterminal with the same configuration(as labview) I can press "ctrl+b" and instrumnet responds. what is different?

    I think what you need to do is send the byte value for STX which I think is 02 hex. There are a few ways to do this. The easiest way to do so is to right click on a text control and select hex display. Now type 02. Change it back to normal display if you want to type in the rest of your message. Connect this control to serial/VISA write. This should be the same as type "ctrl+b" in HyperTerminal.
    Let me know if this doesn't help you.
    Brian

  • I have already tried to disable the message to open all windows on restart through System Preferences.. No matter what I do, I cannot override this feature? Any thoughts?

    I have tried to override the feature found in the close/restart dialog box on reboot or shutdown. I have clicked the box on the dialog box and it continus to reopen pevious windows. I tried changing the setting in System Preferences, with no luck. Any ideas?
    Thanks,
    Joe Dianda

    See "Hang at exit":
    *http://kb.mozillazine.org/Firefox_hangs
    *https://support.mozilla.com/kb/Firefox+hangs

  • Overriding Ctrl + Tab of JTabbedPane

    Dear All ,
    I have registered a keyboard action (ctrl+Tab key) to the
    JTabbedPane instance in my program for " Shifting TabbedPane's Tabs " . But its not working. If i register with ( Ctrl + any other key )     it working fine.     
         MY CODE:
         sm_tabpaneGUI.registerKeyboardAction(rightAction,KeyStroke.getKeyStrokejava.awt.event.KeyEvent.VK_TAB,java.awt.Event.CTRL_MASK),JComponent.WHEN_FOCUSED);
         where rightAction is an ActionListener object reference which does the necessary functionality.
    But Acc. Bug Id 4481587 they have given a workaround.
    " Edit the awt.properties files which have the focus traversal keys defined. "
    It is not working. So any other workaround would be appreciated."
    Srinivasan Samivelu
    Software Development Engineer
    BarcoNet Private Limited.
    Mailto:[email protected]
    http://www.barconet.com

    try dropping this into your app ..
    DefaultFocusManager myManager = new DefaultFocusManager(){
         public void processKeyEvent(Component focusedComponent, KeyEvent anEvent)
         // Returning when you receive CTRL-TAB makes your components able to control that key
         if (anEvent.getKeyCode() == KeyEvent.VK_TAB && (anEvent.getModifiers() & KeyEvent.CTRL_MASK) == KeyEvent.CTRL_MASK)
              return;
         super.processKeyEvent(focusedComponent,anEvent);
    FocusManager.setCurrentManager(myManager);

  • Cannot override logout after 20 mins of inactivity

    Here's an odd one.
    I have a couple of iMacs that have the option to "logout after 20 mins of activity" ticked in security preferences.
    I don't want this to happen, so as an administrator I can uncheck the option and click the padlock icon to prevent changes.
    However, even with the option unchecked, they'll still log out after 20 mins, and when I revisit the security preferences page again, the option will be ticked again.
    Any clues, anyone?

    Thanks for the reply, but I've tried clicking the padlock and also leaving it alone.
    The result is always the same. If I uncheck the the logout option, or change the number of minutes, *it always returns to the same settings when I navigate away from the security preferences*, and then return to them.
    There is no "save settings" option, and other checkboxes, like the "require password" option IS retained if I check it.
    It's just the automatic logout setting.
    This is really frustrating. I didn't setup these particular Macs.
    Is there another setting elsewhere that could be overriding this?
    Or a preference file to delete?
    I really don't understand what's going on.
    Any help much appreciated.

  • Cannot override protected fields

    I know this is not possible, but my question is why did they design it
    that way:
    public class ParentForm {
    protected String name = "ParentForm";
    protected String getName(){return name;}
    public class ChildForm extends ParentForm{
    protected String name = "ChildForm"; //I am trying to override
    the field value but reuse the method from parent.
    public class Test {
    public static void main(String[] args) {
    System.out.println((new ParentForm()).getName());
    System.out.println((new ChildForm()).getName());
    Output:
    ParentForm
    ParentForm
    I wanted to see "ChildForm" in the second line. Why do I have to
    duplicate (literally cut and paste) the getName() method in the child
    to achieve it ?
    Can someone explain the concept I am missing ?

    Wouldn't it be good have the privilege ofsaying,
    "I
    am extending your class wherein I want to
    inherit
    everything from you except override the value ofthis
    one field" ? I've never encountered a situation where thatwould
    be useful.Well, it will surely save a lot of unnecessary coding
    writing dummy methods.I've never had to write dummy methods.
    Like I said, I think the real problem is in your design.

  • Cannot override codebase to use local files for first time installation.

    I have an application that is installed via a JNLP link. The application is about 200MB and we use a web start so that each time the application starts it checks for updates in the configuration and downloads them if necessary.
    I have a requirement to provide an offline installation on CD as some of our users have very slow connection speeds and it's taking over an hour to download the binaries.
    I am trying to do the install using the command line javaws -import -codebase <linktolocaldir> <linktojnlp>
    I need to use the jnlp on the sever so that the configuration files are checked and downloaded each time it starts.
    However the local codebase is never used - the dialog always says that it is downloading from the server, I can only get it to install from the local drive if I change the path directly in the JNLP (which is no good as I need to keep this path pointing to the server)
    Is there any other way to override the codebase for the initial installation?
    Any help much appreciated.

    Here are the guides I've used to do mine:
    How to use the Java Web Start CD-Install feature ? http://download.oracle.com/javase/1.5.0/docs/guide/javaws/developersguide/cdinstall.03.06.html
    Distributing a Java Web Start Application via CD-ROM http://blogs.oracle.com/CoreJavaTechTips/entry/distributing_a_java_web_start
    Distributing a Java Web Start Application via CD-ROM (same as above) http://www.java.net/pub/a/today/2008/07/10/distributing-web-start-via-cd-rom.html

  • Cannot Override Windows Bootloader [SOLVED]

    I have two HDDs--one with Windows 7 and one with Arch64. I recently installed Arch to the second HDD and I can't override the Windows Bootloader; when I start my PC, GRUB is skipped entirely and I boot right into Windows 7. I have already made the Arch HDD the first boot priority in my BIOS, so I'm not sure where to go from here. I thought maybe remove the bootable flag from the Windows HDD, but I can't do that with the LiveCD (cfdisk can't read that drive).
    Suggestions?
    Last edited by Xs1t0ry (2009-10-06 01:03:01)

    Xs1t0ry wrote:
    I have two HDDs--one with Windows 7 and one with Arch64. I recently installed Arch to the second HDD and I can't override the Windows Bootloader; when I start my PC, GRUB is skipped entirely and I boot right into Windows 7. I have already made the Arch HDD the first boot priority in my BIOS, so I'm not sure where to go from here. I thought maybe remove the bootable flag from the Windows HDD, but I can't do that with the LiveCD (cfdisk can't read that drive).
    Suggestions?
    Neither partitions should have the bootable flag on, actually. Make sure that the GRUB loader is being installed to the actual MBR. For instance, if your harddrive partitions are marked as SDA1, SDA2... etc.. then make sure that the bootloader is being installed to just SDA.

  • I cannot override my previous version of Firefox with v4.0. When I try to drag it into applications, I get a message that there is a newer version already there (not true).

    I have been following the download instructions. But I never get a prompt to place the file into the Applications folder. So I open the file, drag it to Applications, and get a message that I already have a newer file in Applications. However, this is not true. When I drag the file to the Firefox icon, I am told that can't be done because Firefox is already open.
    I have done several other updates, never had this problem before. I have a MacBook.

    Beginning with Firefox 4, Macs must have an Intel x86 processor; your system is a PPC Mac.
    *System Requirements: [https://www.mozilla.org/en-US/firefox/4.0/system-requirements/index.html Firefox 4] [https://www.mozilla.org/en-US/firefox/5.0/system-requirements/index.html Firefox 5] [https://www.mozilla.org/en-US/firefox/6.0/system-requirements/index.html Firefox 6] [https://www.mozilla.org/en-US/firefox/7.0/system-requirements/index.html Firefox 7] [https://www.mozilla.org/en-US/firefox/8.0/system-requirements/index.html Firefox 8]
    The good news is that Firefox 3.6.24 still supports the PPC Mac architecture. The bad news is that support for the Firefox 3.6.x series is likely to end in the first quarter of 2012.
    *System requirements: [https://www.mozilla.org/en-US/firefox/3.6/system-requirements/index.html Firefox 3.6.x]
    *Download Firefox 3.6.24: https://www.mozilla.org/en-US/firefox/all-older.html
    You can try the third-party product '''''TenFourFox''''' that supports PPC Macs. Firefox 8 version of '''''TenFourFox''''' is available. The product is based on Firefox released versions. All support is provided by the developer, not by this site:
    *Home page: http://www.floodgap.com/software/tenfourfox/
    *Developer's blog: http://tenfourfox.blogspot.com/
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''

Maybe you are looking for