Mnemonic on button : CTRL + N instead of ALT + N

Hello,
Can anyone help me.
When I push CTRL + N in a screen, I would like a button to be clicked.
A mnenomic is working with ALT + N. But it must be CTRL + N.
Is this possible ?
Grtz

Alt is the standard mnemonic modifier on Windows, so you get this behavior for free from the JDK.
If you want to support other keystrokes, you will need to do this manually. You can do so by inserting entries into the action map and input map of the panel containing your button.
Here's an example that installs an action for Ctrl+N:
package project1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestPanel extends JPanel
  private final JButton _button = new JButton();
  private final JLabel _label = new JLabel();
  public TestPanel()
    setLayout( new BorderLayout( 0, 15 ) );
    add( _button, BorderLayout.CENTER );
    add( _label, BorderLayout.SOUTH );
    _button.setAction( new AbstractAction( "New" ) {
      public void actionPerformed( ActionEvent e )
        _label.setText( "Clicked!" );
    _button.setMnemonic( 'N' );
    getActionMap().put( "clickButton", _button.getAction() );
    getInputMap( WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ).put(
      KeyStroke.getKeyStroke( "control N" ), "clickButton" );
  public static void main( String[] args )
    JFrame f = new JFrame();
    f.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
    f.setContentPane( new TestPanel() );
    f.pack();
    f.setVisible( true );
}Thanks,
Brian

Similar Messages

  • How to Mnemonic  a button

    i just need to mnemonic a button , when i type 'a' in key board
    the button1 will be pressed, when type 'b' the button2 will be pressed
    there is a method button.setMnemonic('H') , it will works when pressing
    ctrl + a or ctrl + b
    but is it possible when i press a the button get the invoke the action and
    gets the effect like when press click from mouse

    You can use input and output mappings, like below:
         * Creates the mapping from a key to a button
         * @param  parent   the panel containing the button
         * @param  keycode  the keycode for the mapping
         * @param  button   the button to be mapped
       private static void createButtonMapping(JPanel parent, int keyCode, JButton button) {
          InputMap im = parent.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
          ActionMap am = parent.getActionMap();
          String mapString = "action_" + keyCode;
          im.put(KeyStroke.getKeyStroke(keyCode, 0), mapString);
          am.put(mapString, createButtonAction(button));
         * Creates the action corresponding to a button
         * @param  button   the button to be used
       private static AbstractAction createButtonAction(final JButton button) {
          AbstractAction buttonAction = new AbstractAction() {
             public void actionPerformed(ActionEvent e) {
                System.out.println("action "+e+" has been performed...");
                button.doClick();
          return buttonAction;
       }Then you just have to create each mapping as needed.
    PS: of course, this won't work in components who intercept mappings by themselves (JTextField for example)

  • When I have finished working on an image in Photoshop and I hit the save button it goes instead to the "save as" screen. This never happened in previous Photoshop versions. When I get to Lightroom, I have a grey screen the says "File could not be found."

    When I have finished working on an image in Photoshop and I hit the "save" button, it goes instead to the "save as" screen. This never happened in previous Photoshop versions. When I get to Lightroom, I have a grey screen the says "File could not be found." I then have to go to "locate" to get the image. When I select the correct image, I get a message that it is not the same file name but I am eventually able to access the image. Needless to say this is having a negative impact on workflow!

    The problem with write permissions for the OneDrive folder only shows up in Lightroom 6's export dialogue, that's why it's to irritating. Lightroom 5.7.1 is not having that problem nor does the file explorer. The problem also exists on both of my machines. I will try to check for other problems with the OneDrive troubleshooter though: Running the OneDrive troubleshooter - Windows Help   

  • Two New Emergency buttons are coming instead of one in ESS.

    Hi All,
    Two New Emergency Contact buttons are coming instead of one for International Users (For USA it's working fine) in Emergency Contact of ESS.
    We are unable to find out from where this got configured.
    Could you please help us to solve this issue?
    Appreciate of any help with this regards.

    Hi Yugandhar,
    Thanks for your reply!!
    Everything is work fine except this scenario.

  • My minimize button is black instead of colored

    I have a 15" Macbook Pro Retina and for some reason my close/minimize/maximize buttons are black instead of red/yellow/green.. I tried to look through the setup but could not find anything to change these.. Where is this setup?
    Thanks
    Gary

    So what you trying to say? You don't like black buttons?
    Lol jk.
    Try System Preferences > General > Appearance > Change to Blue, if its set on Graphite.
    That's the only thing I know that changes the color of those icons.  Hope it helps!

  • Delete button deletes forward instead of backward

    All of a sudden my delete button deletes forward instead of backward on my bluetooth keyboard that I'm using with my G% tower.  Any ideas how to get it back?

    Curious, perhaps Spark could help with the problem...
    http://www.shadowlab.org/Software/spark.php

  • Acces key - CTRL KEy instead  ALT key

    hi,
    in ADF components access key is working based on Alt key for IE ,
    is it possible to set access key with Control key ?
    is it possible to set Function keys as access keys ?
    please advice
    Regards
    Jeethi George

    Hi,
    you can define function keys using the af:clientListener and JavaScript. The default usage of ALT cannot be changed
    Frank

  • Menu Buttons Change Image instead of Highlighting?

    Does anyone know how to/or if it's possible to make a DVD menu in Photoshop for Encore where, when the menu button is highlighted it actually changes image instead of making it a solid highlighted colour?
    For example...
    In a DVD i'm making, I have Cartoon images that are the menu buttons. I would like to make it so that when you select it on your dvd player it makes the eyes open up wider and mouths of the characters open up. I have made the duplicate layers and changed one to have the open eyes and mouth and placed it directly ontop of the other and put both layers in the one group with the (+) to allow Encore to recognize it. But all I get is the top layer of the two turning to a top colour. I know that using prefixes like (=1) makes it highlighted and that is why it's highlighting but I don't know what else to suggest. I've looked at the prefixes on the Encore help on this site and tried to work it out but no luck
    I know this is due to my lack of knowledge and really need some help to fix it, or know if it's even possible (I assume tht using such great products as Adobe it will be)
    Thanx

    Welcome to the forum.
    This is easily done by doing dupe Menus for each Button. The Button on the original Menu will be set to Auto-Activate, and be linked to the dupe Menu with the different graphic. I would probably turn OFF Sub-picture Highlights.
    The trick is to do a layout, and also name your Menus (especially the dupes), to reflect exactly what they do. I use Illustrator for my layout, but pencil and paper work well too.
    Note: if run on a computer, the user will need to Dbl-click the Button, as Auto-Activate only works seamlessly from a DVD set-top player.
    There are several other posts on this forum (a few very recent), where I go into much more detail. Also, Jeff Bellune's excellent book, The Focal Easy Guide to Adobe EncoreDVD 2.0, by Focal Press, has excellent, easy to follow steps for doing this. Though written for EncoreDVD 2.0, 100% of the book will apply to CS3 & CS4.
    Good luck,
    Hunt

  • Can i create the printer button like before instead of the 4 steps now

    My printer button has disappeared. Now going to the menu button it takes 4 clicks to print instead of one. Can I create a print button to eliminate steps?

    Try this add on: [https://addons.mozilla.org/en-US/firefox/search/?q=create+custom+buttons&appver=29.0&platform=windows custom buttons]

  • Is there a way to switch between different tabs using your keyboard (eg CTRL+T) instead of clicking with the mouse?

    I would like to you use the keyboard to switch between tabs but I couldn't find if this is possible.

    Ctrl + Tab

  • Use Buttons as counters, instead of numbers

    I have a basic slideshow, with previews and next buttons replacing the arrow text (>). What i am trying to do now, is to replace the counter, with buttons.  I have 5 photos, and i would like to link all 5 photos to a different button at the bottom of the screen.  The slideshow can still autoplay, but if a user wants to see a photo again, they click the corisponding button to go back to it.  Each button changes to a different color when active, and have a role over bar that connect to them all.  All of that is doable with the place photoshop button, but i don't know how to link the buttons to the photos.
    Any help out?
    Thanks

    Hi,
    Unfortunately, there is no out of the box solution to replace the counters with buttons and link them with the respective slideshow image at the moment,
    Regards,
    Aish

  • Power Mac G4 power button activates sleep instead of shut down.

    I am setting up my G4 as a 'backup' machine for a macbook pro. The G4 will not have a monitor attached, so I will not have access to the normal 'Apple>Shut Down' menu or key commands.
    The power button on the G4 powers up the machine just fine, but pushing the power button to turn the machine off seems to put the system to sleep (including the monitor) but doesn't shut anything off.
    Any ideas as to what could be causing this or how to fix it? Thanks in advance!
    Message was edited by: Host <to clarify Title>

    Hi, Ryan -
    If you are using an Apple Pro keyboard on that machine, there is a set of keystrokes which may allow you to shut it down 'in the blind' (they work with OS 9; not sure about OSX) -
    Press the key combo Option-Eject (Eject is the topmost-rightmost key above the keypad). This should bring up a splash screen displaying buttons for Restart, Sleep, Cancel, and Shutdown. As I recall, the default (heavy-border or blue) button is Shutdown - pressing Return or Enter should engage it.
    Note - not sure if the modifier used with Eject is Option (I think it is) or another one... I don't have a machine available at the moment which has an Apple keyboard on it with which to test.

  • My Airport button is yellow instead of green in the network status

    i cant get on the internet, i have never had trouble before but now the button is yellow and wont turn back to green. i have tried to get renew the ip address, but it remains yellow. can anyone help me?
    thanks
    frustrated mac user

    Try shutting down all items on your network and erstarting them one at a time. Most likely your DHCP server device has gotten stuck.

  • Opening the pages large on a laptop 18.4inch;now the pages open small eni must always large d'them with the buttons ctrl and +

    When i start firefox the pages open small (not the window) (on my laptop 18.4 inch)
    i can enlarge them by pushing ctrl and +.
    Can i make that the pages open large so i dont have tu push always on ctrl and+.
    Wanneer ik firefox open op mijn laptop 18.4 inch opend het scherm wel groot maar de tekst opend klein,dit los ik op door ctrl en + toetsen in te drukken maar.hij onthoud dit niet en telkenmalle als er een nieuwe pagina opent moet ik opnieuw ctrl en + toetsen indrukken en dat werkt niet gemakkelijk
    een oplossing hiervoor graag

    You can use an extension to set a default font size and page zoom on web pages.
    *Default FullZoom Level: https://addons.mozilla.org/firefox/addon/default-fullzoom-level/

  • Why does the email button attach xml instead of pdf?

    Sorry, it's probably a stupid question, but I can't figure it out! Thanks a million!

    Hi Diana. You can use the Button object (not a Submit button) and modify it to submit the PDF version of your document.
    After you've placed a button in your layout;
    1) click on the Object tab
    2) Select "Submit" as your Control Type
    when you've done this, a "Submit" tab will appear
    3) Click on the "Submit" tab
    4) Change the "Submit Format" to "PDF"
    5) Add the e-mail address in the "Submit to URL" field (as below);
    mailto: [email protected]

Maybe you are looking for

  • Nokia 'push' email no longer pushing after service...

    Had my e71 for a couple of weeks and i was quite happy, then i recived an email from nokia telling me they were updating my service and unless i re-entered my email password in email settings i would no longer get my emails pushed to my phone. I foll

  • Grand Total For Matrix Based Report

    Hi All, I have a matrix based report with Fields like Country ,Amount and MonthYear So report looks like below the columns get generated dynamically : Country     Oct 2013    Nov 2013  Dec 2013 India         25,000         25,000    25,000 England   

  • Content Categorizer excel parsing issue

    Dear All, Need your help with the UCM Content Categorizer issue. I have an excel which i am trying to pass thru content categorizer to generate custom metadata suggestions. I have the rulesets defined as per requirements in categorizer admin applet.

  • Freezing on save in captivate 6 (mac)

    A lot of the time when I save my project it gets to 50% and freezes, is there a way to stop this from happening?

  • Normal GL planning upload

    Hi, We are not activated new GL. but we need to upload plan values against expenses and revenues. We need to upload the same by Period wise and GL wise through tcode FSE5N. But FSE5N is not flexible to upload period wise and GL wise. Can anyone guide