JTextPane key bindings override JMenuItem accelerators

hi all,
I have a JTextPane subclass, sitting on a JPanel, sitting on a JFrame which has a JMenu attached. One of my menu commands has an accelerator PgDn... I am trying to disable the PgDn default behaviour in the JTextPane so that the keystroke then "falls through" and activates the menu item...
NOTHING WORKS! Using Keymap and InputMap, have tried "remove", have tried setting the action to "none", etc... it is simple enough to stop PgDn default behaviour in JTextPane, and if I looked into it I could probably explicitly put the action of the menu item in the action map of the JTextPane... but I want to cancel the key binding so that the system looks elsewhere and finds the JMenuItem accelerator...! is this too much to ask??
I am a big user of hotkeys in apps and I want to understand more about all this stuff... how come there are no fewer than 4 generations of InputMap associated with a single JTextPane, for example?
Thanks
Mike

Hi,
Thanks for this... very useful clue... In fact JTextPane itself does handle the PgDn key binding, causing the insertion point to move to the end of the multiline text.
But I followed your suggestion, finding that it is, perhaps unsurprisingly, the vertical Jscrollbar which (otherwise) handles PgDn, causing a scroll down... and a little experimenting finds that this scrollbar is created not on the fly, but once for each JScrollPane...
So I also remove the vertical JScrollBar's key binding for "PgDn" (listing the bindings before and after removal) and... it STILL refuses to work!
So I thought: aha, maybe by some anomaly you have a PgDn binding in the horizontal scrollbar... turns out it seems to share the same input map (actually the parent of the JScrollBar's getInputMap()) as the vertical scrollbar... so no, this doesn't work either!
I also checked out scrollpane's viewport... 0 keys in getInputMap() and the latter does not have parent...
Your suggestion looks like a very promising avenue... somewhere there is something trapping this key, but what? NB when a JButton, for example, is placed on the JPanel, and focus is on the button, PgDn activates the JMenuItem accelerator as expected, so it's obviously sthg to do with the complexity of having a JScrollPane combination
Anything else you can suggest? I really don't want to have to explicitly put an action in the JTextPane... I like to understand, and I like elegant solutions...
Thanks,
Mike

Similar Messages

  • Problem: sqldeveloper 1.5 key bindings in mac os x

    Hi -
    I just installed the new sqldeveloper (1.5.0.53.38) on Mac OS X Leopard, and when I try to edit sql queries in the worksheet, I'm finding that many keys don't work. For example, the spacebar and delete keys do nothing.
    I tried loading various different accelerator presets:
    - after loading "Default MacOS X" set, neither space nor delete keys do anything
    - after loading "Default", "Classic" or "Brief" sets, the spacebar works, but not delete
    I tried to fix this by changing the accelerators through the Preferences UI, but I couldn't figure out how to assign the 'backspace' key to the 'delete-previous' accelerator (since it doesn't seem possible to type the actual backspace character in the keystroke box...). I was able to fix the delete key by editing settings.xml by hand, changing this:
    <Item class="oracle.javatools.util.Pair">
    <first class="java.lang.String">delete-previous</first>
    <second class="oracle.ide.keyboard.KeyStrokes">
    <data>
    <Item class="javax.swing.KeyStroke">[0]</Item>
    </data>
    </second>
    </Item>
    to this:
    <Item class="oracle.javatools.util.Pair">
    <first class="java.lang.String">delete-previous</first>
    <second class="oracle.ide.keyboard.KeyStrokes">
    <data>
    <Item class="javax.swing.KeyStroke">[8]</Item>
    </data>
    </second>
    </Item>
    I was able to get the spacebar to work again by removing the association between the spacebar key and the completion-insight accelerator, using the Preferences UI.
    So, my questions are:
    - Do I have some weird setup where my delete key is [8] instead of [0]? I'm trying to tell if this is a problem with my environment or with the settings that are shipped with the product.
    - If it's the latter, could the default MacOS X accelerator settings be updated? I seem to remember this same problem happening the last couple of times I installed a new version of SQL Developer.
    Let me know if there's any other information I could provide that would be useful.
    Thanks!

    Another problem I found with the MacOS X key bindings: the 6 key doesn't work!
    In the config that ships with SQL Developer, I found this:
    <Item class="oracle.javatools.util.Pair">
    <first class="java.lang.String">DOCUMENT_6_CMD_ID</first>
    <second class="oracle.ide.keyboard.KeyStrokes">
    <data>
    <Item class="javax.swing.KeyStroke">6</Item>
    </data>
    </second>
    </Item>
    which should be:
    <Item class="oracle.javatools.util.Pair">
    <first class="java.lang.String">DOCUMENT_6_CMD_ID</first>
    <second class="oracle.ide.keyboard.KeyStrokes">
    <data>
    <Item class="javax.swing.KeyStroke">meta 6</Item>
    </data>
    </second>
    </Item>

  • Control-k key binding broken. How can I check and change my key bindings?

    I use the Terminal app a lot. Unfortunately I am not able to use the control-k shortcut to cut lines in the terminal anymore. How can I check (and change) the Terminal key bindings?
    Thank you!

    Basing on your input, you should get the following values:
    1) session keys
    SK_ENC: 6DCE2A99BACB5207A7A96A92F114D66C
    SK_MAC: 0D446132B168F75CD6F0A780693A4DD3
    SK_DEK: 19F7B0F94837F32874B29B5EFB7809F6
    2) host cryptogram
    1B781553209748EA
    3) Retail MAC
    01761103B810F00E
    Summing up, the External Authenticate command should have the following value:  84 82 01 00 10 1B781553209748EA 01761103B810F00E.
    Try to compare it with your results.
    Regards

  • Key Bindings using the arrow keys

    Following is some code that allows you to move a component around the screen using the arrow keys. I've noticed a problem and I'm just wondering if its Java or my keyboard.
    Lets start with an example that works:
    Press the down and right keys. Then press either the up or left key. The image moves proving that it supports 3 keys.
    Now for the problem:
    Press the up and left keys. Then press either the down or right key. Three things to notice:
    a) the direction doesn't change when the third key is pressed
    b) no output is displayed, so the ActionListener is not being invoked
    c) after a short time, the program starts beeping
    Now try rerunning the code after removing the comments that assign the key bindings to the "a, s, d, f" keys. Redo the above test and it works even if all four keys are pressed.
    I don't remember this problem when I wrote the code a while ago, but I did recently get a cheap new keyboard so I'm just wondering if the problem is my keyboard or whether its a quirk with Java.
    You can download Duke from here:
    http://java.sun.com/docs/books/tutorial/uiswing/examples/components/LayeredPaneDemoProject/src/components/images/dukeWaveRed.gif
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class KeyboardNavigationProblem implements ActionListener
         private JComponent component;
         private int deltaX;
         private int deltaY;
         private Timer timer;
         private int keysPressed;
         private InputMap inputMap;
         public KeyboardNavigationProblem(JComponent component, int delay)
              this.component = component;
              this.deltaX = deltaX;
              this.deltaY = deltaY;
              timer = new Timer(delay, this);
              timer.setInitialDelay( 0 );
              inputMap = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
         public void addAction(int keyCode, String description, int deltaX, int deltaY)
              new NavigationAction(keyCode, description, deltaX, deltaY);
         public void updateDeltaX(int delta)
              deltaX += delta;
         public void updateDeltaY(int delta)
              deltaY += delta;
         public void actionPerformed(ActionEvent e)
              int componentWidth = component.getSize().width;
              int componentHeight = component.getSize().height;
              Dimension parentSize = component.getParent().getSize();
              int parentWidth  = parentSize.width;
              int parentHeight = parentSize.height;
              //  Determine next X position
              int nextX = Math.max(component.getLocation().x + deltaX, 0);
              if ( nextX + componentWidth > parentWidth)
                   nextX = parentWidth - componentWidth;
              //  Determine next Y position
              int nextY = Math.max(component.getLocation().y + deltaY, 0);
              if ( nextY + componentHeight > parentHeight)
                   nextY = parentHeight - componentHeight;
              //  Move the component
              component.setLocation(nextX, nextY);
         class NavigationAction extends AbstractAction implements ActionListener
              private int deltaX;
              private int deltaY;
              private KeyStroke pressedKeyStroke;
              private boolean listeningForKeyPressed;
              public NavigationAction(int keyCode, String description, int deltaX, int deltaY)
                   super(description);
                   this.deltaX = deltaX;
                   this.deltaY = deltaY;
                   pressedKeyStroke = KeyStroke.getKeyStroke(keyCode, 0, false);
                   KeyStroke releasedKeyStroke = KeyStroke.getKeyStroke(keyCode, 0, true);
                   inputMap.put(pressedKeyStroke, getValue(Action.NAME));
                   inputMap.put(releasedKeyStroke, getValue(Action.NAME));
                   component.getActionMap().put(getValue(Action.NAME), this);
                   listeningForKeyPressed = true;
              public void actionPerformed(ActionEvent e)
                   if (listeningForKeyPressed)
                        updateDeltaX( deltaX );
                        updateDeltaY( deltaY );
                        inputMap.remove(pressedKeyStroke);
                        listeningForKeyPressed = false;
                           if (keysPressed == 0)
                                timer.start();
                     keysPressed++;
                   else // listening for key released
                        updateDeltaX( -deltaX );
                        updateDeltaY( -deltaY );
                        inputMap.put(pressedKeyStroke, getValue(Action.NAME));
                        listeningForKeyPressed = true;
                        keysPressed--;
                           if (keysPressed == 0)
                                timer.stop();
                   System.out.println(KeyboardNavigationProblem.this.deltaX + " : "
                   + KeyboardNavigationProblem.this.deltaY);
         public static void main(String[] args)
              JPanel contentPane = new JPanel();
              contentPane.setLayout( null );
              JLabel duke = new JLabel( new ImageIcon("dukewavered.gif") );
              duke.setSize( duke.getPreferredSize() );
              duke.setLocation(100, 100);
              contentPane.add( duke );
              KeyboardNavigationProblem navigation = new KeyboardNavigationProblem(duke, 100);
              navigation.addAction(KeyEvent.VK_LEFT, "zLeft", -5, 0);
              navigation.addAction(KeyEvent.VK_RIGHT, "zRight", 5, 0);
              navigation.addAction(KeyEvent.VK_UP, "zUp", 0, -5);
              navigation.addAction(KeyEvent.VK_DOWN, "zDown", 0, 5);
    //          navigation.addAction(KeyEvent.VK_A, "zLeft", -5, 0);
    //          navigation.addAction(KeyEvent.VK_S, "zRight", 5, 0);
    //          navigation.addAction(KeyEvent.VK_D, "zUp", 0, -5);
    //          navigation.addAction(KeyEvent.VK_F, "zDown", 0, 5);
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.setContentPane( contentPane);
              frame.setSize(800, 600);
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

    if you hold down left and right (so it doesn't move), down works, but not up.
    hold up/down, right works but not left.Yes, the problem only seems to be when the up and left in combination with the right or down key is pressed.
    num lock off - use the number pad arrow keys and all works OK Thats interesting, I didn't notice that. Although it just confuses the issue as to what the problem is.
    So it appears to me that:
    a) left + up + down, and
    b) left + up + right
    are special key combinations that are intercepted by either the OS or the JVM. Do these key combinations ring a bell to anybody?
    I'm use JDK1.4.2 on XP. I wonder if other OS will have the same problem?
    Again, this isn't a real, problem, just more of a curiosity. Thanks,

  • Cut/Copy/Paste - How to set the key bindings ?

    Hi,
    I'm currently using the motif LnF in Windows. It matches the colors and style I want.
    The problem is: people using Windows want to use the standard windows key bindings (that is: CTRL+V, CTRL+C, CTRL+X) instead of the Motif ones.
    Does anyone how to set the old Windows key bindings into the Motif LnF ?
    If anyone can provide some light, it'd be great !
    Regards,
    - Juancho

    The Swing tutorial on "General Rules for Using Text Components" has a demo program that shows you how to assign KeyStrokes to Actions.
    Unfortunately the demo has not been updated in a while and still uses a keymap. The new approach would be to use an 'inputMap' and an 'actionMap'. The code for the copy action would be something like this:
    textComponent.getInputMap().put(keyStroke, "copy");
    textComponent.getActionMap().put("copy", action);
    Again, the demo program 'TextComponentDemo' from the above tutorial will show you how to:
    1) create the keyStroke for Ctrl+C
    2) retrieve the default copy action from the editor kit

  • Problem changing default key bindings using Oracle Terminal

    Hello,
    I'm facing a problem changing default key bindings using Oracle Terminal. I changed
    some bindings, saved them in forms60/fmrusw.res, started the generation and saved again.
    I thought that's it but it wasn't. It took no effect at all in Forms (even after recompilation) although reopening the file in Terminal showed the changes. I'm using Forms in German, which means that even the key bindings displayed in Forms are translated i.e. STRG+F1 instead if CTRL+F1,
    but I can't find a german version of this resource file, so i think it's the same resource file for all supported languages. But what is needed for the changes to take effect ?
    Thanks in advance
    STD
    null

    Hi,
    is it client/server you are working?
    if so you should not be using the fmrusw.res file because I guess your NLS_LANG is German_Germany.WE8ISO8859P1 or something like that. This means the terminal that is being opened is fmrdw.res instead of fmrusw.res and this file should be edited using Oracle Terminal.
    if you are working via the web implementation than you can open the file fmrweb.res in a text editor and change the keybindings in there. If you need to have the PC like key bindings on the web just open the fmrpcweb.res and see if it contains the German texts. If so you can either copy this file over the frmweb.res file or you can specify term=fmrpcweb.res in the serverargs parameter.
    Hope this helps.
    Kind regards,
    Frank van der Borden
    Oracle Support Services
    Netherlands

  • Forms Key-Bindings in Windows

    Is there any way to disable the key bindings in a forms
    application without editing the windows resource file
    (FMRUSW.RES) in Oracle Terminal? I know that the key-bindings
    can be suppressed in the Key-Others trigger, but how do you refer
    to the specific key you want to disable?
    Any help is appreciated. Thanks in advance.
    null

    Hi
    There are over 1000 user-definable key commands in Logic, with many already defined in a variety of presets. I'd suggest using the standard US set (with no numbers keys)
    http://documentation.apple.com/en/logicpro/usermanual/index.html#chapter=8%26sec tion=4%26tasks=true
    HTH
    CCT

  • How to customize key bindings, say emacs-like.

    I have been able to install keyconfig, but I can't find the code for simple things like:
    forward-char
    backward-char
    move-beggining-of-line
    move_end-of-line
    and other emacs-like commands.
    The page
    http://kb.mozillazine.org/Keyconfig_extension:_Thunderbird
    has a long list of command I can shortcut, but none of the simple ones I need to navigate
    the composition window, in emacs-like style.

    Yes, left and right arrows do the job, as well as Home and End keys. However, being a regular emacs user, it takes me less time and comes more natural to find C-f, C-b, C-a and C-e on the keyboard.
    I actually have TB on two machines, home and work. In one of them the emacs-like key bindings work, but not on the other machine, even though they are running the same version of Mac OS and TB.

  • Changing key bindings in xcode

    I have quite a simple problem: a good portion of the key bindings i set in Xcode simply don't work.
    Example: I set "code sense select next placeholder" as command+E on my desktop..yet on my laptop when I set it to that, it just beeps when I push command+E.
    Second Example: I want to change the default key for popping up the class/method list [currently control+2], but it won't let me change it to command+2, or most other things for that matter. I've had so many problems I don't think ALL of the conflicts can be system/xcode presets that are unchangable.
    How do I force Xcode to use the key bindings I want?
    alternately: How do I see which programs are keeping Xcode from recognizing the key bindings I set?
    Thanks,
    Nick

    xcode 3 fixed this problem. hooray!

  • Terminal key bindings for Home and End

    I am recording this here in the hope of savings others some time.
    It is often stated that the following Terminal key bindings have to be asserted to get Home and End keys working as intended:
    \033OH
    \033OF
    I find this misleading as it is neither what most people would type nor what they would see.
    I type:
    escape O H
    escape O F
    This results in:
    \033oh
    \033of
    which works as intended but using 'shift' to produce the capitals depicted in most notes about this will not work.

    My default bindings did not work for home and end but page up and page down inexplicably worked with shift. The image below shows the keys and their bindings (eg \033[5~ and \033[6~ stated here for Google!) I applied to Terminal to make home, end, page up and page down behave in the same way as many other applications including iTerm. Remember to type 'esc' to get '\033'.
    I started out trying to improve the readability of large manual pages (eg man bash). Whilst the changes above improved things considerably I have now found better alternatives.
    I tried iTerm - the keys worked correctly but inconsistencies between the various window size settings did not inspire confidence.
    I now use ManOpen.app which I have configured to open when I type eg 'm chmod' in Terminal - I changed the name of openman to m and put it together with openman.1 in /usr/bin. The pages scroll normally and have hot links to other manual items. This is a simple way to vastly improve manual reading. The only slight negatives I have found are:
    1 - two preference panes will not open - defaults OK for me
    2 - window positions not remembered - since size can be set I can live with this
    3 - text cannot be set to soft wrap to window width (misnamed zoom by some applications).
    I would be interested to hear if others have found better ways of viewing manuals.
    Here are some interesting pages:
    http://en.wikipedia.org/wiki/Tableof_keyboard_shortcuts#Command_lineshortcuts
    http://www.tuaw.com/2008/03/07/here-comes-your-man-viewer/

  • How to modify Emacs key bindings in XCode?

    I'm trying to do an emacs "undo" (ctrl-_) and it doesn't work. How do I add this key binding? Is it possible? I'm really trying to use XCode instead of Eclipse, but I'm having a hard time configuring XCode to have all the nice features I use in Eclipse.
    Thanks,
    Alfredo

    Have you tried this?
    1) Xcode menu > Preferences > Key Bindings > Edit
    2) Find the Undo command
    3) Click on Command-Z then hold down ctrl and shift and underscore
    4) Click on Apply
    Bob

  • Portable xterm key bindings

    Hi all,
    I'm looking for a way to define xterm/bash key bindings in a portable/transferable way. Nothing fancy, I'd just love to use Ctrl+Backspace as "backward-kill-word", Alt+d as "kill-word" and so on. So far I had to define a bunch of key bindings in my .bashrc, but what about all those ssh sessions I open?
    Is there a way to automatically transfer key bindings from localhost to any ssh target? Are there terminal emulators other than xterm that can handle this in a sane way?
    To complicate it further, I can't always install my favorite keymaps at work. We do share accounts on some of our servers, my colleagues aren't keen to use my keybindings 'cause they don't seem to work for them.
    I can't even remember how long I've been fighting by this problem, still I don't see any solution for that. Any help is highly appreciated.

    Why not store your ~/.Xmodmap file in the cloud somewhere, then download it where and when you need it. Better yet, install Dropbox on all your machines so that those files you need on each computer sync each time you change them ??

  • InputMap/ActionMap key bindings for arrow keys, alt key

    I'm having trouble defining InputMap/ActionMap key bindings for the arrow keys and the Alt key. My bound actions never run. I believe the problem is that the arrows are used in focus navigation, and the Alt key is used for opening the menu. How can I get these key bindings to work? Is there any other way that I can get events from these keys? I'd even be happy with simple AWT KeyListener events at this point. Thanks.

    I've been having this same problem. I built a demo application that demonstrates the problem. It all works fine until I add the JTree. The JTree seems to be consuming the arrow key strokes. Here is the code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.KeyStroke;
    public class ArrowKeyDemo extends JFrame implements ActionListener {
        private javax.swing.JTree tree;
        private javax.swing.JPanel panel;
        public ArrowKeyDemo() {
            initComponents();
            panel.registerKeyboardAction(this, "A",
                    KeyStroke.getKeyStroke(KeyEvent.VK_A, 0, false),
                    JComponent.WHEN_IN_FOCUSED_WINDOW);
            panel.registerKeyboardAction(this, "left",
                    KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, false),
                    JComponent.WHEN_IN_FOCUSED_WINDOW);
        private void initComponents() {
            panel = new javax.swing.JPanel();
            tree = new javax.swing.JTree();
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    exitForm(evt);
            panel.add(tree);
            getContentPane().add(panel, java.awt.BorderLayout.CENTER);
            pack();
        private void exitForm(java.awt.event.WindowEvent evt) {
            System.exit(0);
        public static void main(String args[]) {
            new ArrowKeyDemo().show();
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println(actionEvent);
    }Having the JTree in there kills the ability to trap key strokes for any other purpose. This seems to be true of other Swing components as well. You can stop the JTree from consuming key strokes by adding the line:
    tree.setActionMap(null);
    But you will probably need to set the ActionMap to null for every Swing component that is trapping key strokes. I'm not 100% sure, but I think that includes scroll panes as well.
    I'd love to hear a more elegant solution.
    --Timothy Rogers

  • JPasswordField affects key bindings

    I set up some key bindings so my program can react to the arrow keys. I came across a rather confusing problem. I've set up a test case to show it:
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import javax.swing.*;
    public class TestCase extends JFrame {
         private static final long serialVersionUID = 1L;
         JPanel contentPane;
         CardLayout cl = new CardLayout();
         public TestCase() {
              super("Terraworld GUI Testing Zone");
              setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              setResizable(false);
              contentPane = new JPanel(cl);
              contentPane.add(new TestTitlePanel(), "Title Screen");
              setContentPane(contentPane);
              pack();
              setVisible(true);
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        new TestCase();
         public void addCard(JPanel card, String name, boolean show) {
              contentPane.add(card, name);
              if(show == true) {
                   cl.show(contentPane, name);
         public void removeCard(JPanel card, String name) {
              contentPane.remove(card);
              cl.show(contentPane, name);
    class TestTitlePanel extends JPanel implements MouseListener {
         private static final long serialVersionUID = 1L;
         JLabel loadCharacter;
         public TestTitlePanel() {
              super();
              setPreferredSize(new Dimension(800, 600));
              loadCharacter = new JLabel("Load Character");
              loadCharacter.addMouseListener(this);
              add(loadCharacter);
         public void mouseClicked(MouseEvent e) {
              if(e.getSource().equals(loadCharacter)) {
                   ((TestCase)(getRootPane().getParent())).addCard(new TestLoadCharacterPanel(), "Load Character Screen", true);
         public void mouseEntered(MouseEvent e) {}
         public void mouseExited(MouseEvent e) {}
         public void mousePressed(MouseEvent e) {}
         public void mouseReleased(MouseEvent e) {}
    class TestLoadCharacterPanel extends JPanel {
         private static final long serialVersionUID = 1L;
         public TestLoadCharacterPanel() {
              super(null);
              setPreferredSize(new Dimension(800, 600));
              add(new LoadCharacterForm());
         public class LoadCharacterForm extends JPanel implements ActionListener, MouseListener {
              private static final long serialVersionUID = 1L;
              JTextField usernameField;
              JPasswordField passwordField;
              JLabel cancelButton;
              JLabel okButton;
              public LoadCharacterForm() {
                   super(null);
                   setBounds(204, 167, 396, 225);
                   usernameField = new JTextField();
                   usernameField.addActionListener(this);
                   usernameField.setBounds(263, 46, 109, 20);
                   usernameField.setFont(new Font(Font.SANS_SERIF,
                             usernameField.getFont().getStyle(),12));
                   usernameField.setText("Default");
                   passwordField = new JPasswordField();
                   passwordField.addActionListener(this);
                   passwordField.setBounds(262, 71, 109, 20);
                   passwordField.setText("Default");
                   cancelButton = new JLabel("Cancel");
                   cancelButton.addMouseListener(this);
                   cancelButton.setBounds(163, 113, 45, 15);
                   okButton = new JLabel("Ok");
                   okButton.addMouseListener(this);
                   okButton.setBounds(347, 113, 28, 15);
                   add(usernameField);
                   add(passwordField);
                   add(cancelButton);
                   add(okButton);
              public void actionPerformed(ActionEvent e) {
                   String username = usernameField.getText();
                   String password = new String(passwordField.getPassword());
                   String error = "";
                   if(!username.equals("") && !password.equals("")) {
                        ((TestCase)(getRootPane().getParent())).addCard(new TestGamePanel(), "Game Screen", false);
                        ((TestCase)(getRootPane().getParent())).removeCard(TestLoadCharacterPanel.this, "Game Screen");
                   else {
                        if(username.equals("")) {
                             error = "Username field is empty!";
                        if(password.equals("")) {
                             if(!error.equals("")) {
                                  error += System.getProperty("line.separator");
                             error += "Password field is empty!";
                        JOptionPane.showMessageDialog(null, error);
              public void mouseClicked(MouseEvent e) {
                   if(e.getSource().equals(okButton)) {
                        actionPerformed(new ActionEvent(usernameField, 1, ""));
                   else if(e.getSource().equals(cancelButton)) {
                        ((TestCase)(getRootPane().getParent())).removeCard(TestLoadCharacterPanel.this, "Title Screen");
              public void mouseEntered(MouseEvent e) {}
              public void mouseExited(MouseEvent e) {}
              public void mousePressed(MouseEvent e) {}
              public void mouseReleased(MouseEvent e) {}
    class TestGamePanel extends JPanel {
         private static final long serialVersionUID = 1L;
         public TestGamePanel() {
              super(null);
              setPreferredSize(new Dimension(800, 600));
              setFocusable(true);
              requestFocusInWindow();
              Action downAction = new DownAction("Down", "Down");
              Action upAction = new UpAction("Up", "Up");
              Action rightAction = new RightAction("Right", "Right");
              Action leftAction = new LeftAction("Left", "Left");
              getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("DOWN"), downAction.getValue(Action.NAME));
              getActionMap().put(downAction.getValue(Action.NAME), downAction);
              getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("UP"), upAction.getValue(Action.NAME));
              getActionMap().put(upAction.getValue(Action.NAME), upAction);
              getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("RIGHT"), rightAction.getValue(Action.NAME));
              getActionMap().put(rightAction.getValue(Action.NAME), rightAction);
              getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("LEFT"), leftAction.getValue(Action.NAME));
              getActionMap().put(leftAction.getValue(Action.NAME), leftAction);
         class DownAction extends AbstractAction {
              private static final long serialVersionUID = 1L;
              public DownAction(String text, String desc) {
                   super(text);
                   putValue(SHORT_DESCRIPTION, desc);
              public void actionPerformed(ActionEvent e) {
                   JOptionPane.showMessageDialog(null, "Down");
         class UpAction extends AbstractAction {
              private static final long serialVersionUID = 1L;
              public UpAction(String text, String desc) {
                   super(text);
                   putValue(SHORT_DESCRIPTION, desc);
              public void actionPerformed(ActionEvent e) {
                   JOptionPane.showMessageDialog(null, "Up");
         class RightAction extends AbstractAction {
              private static final long serialVersionUID = 1L;
              public RightAction(String text, String desc) {
                   super(text);
                   putValue(SHORT_DESCRIPTION, desc);
              public void actionPerformed(ActionEvent e) {
                   JOptionPane.showMessageDialog(null, "Right");
         class LeftAction extends AbstractAction {
              private static final long serialVersionUID = 1L;
              public LeftAction(String text, String desc) {
                   super(text);
                   putValue(SHORT_DESCRIPTION, desc);
              public void actionPerformed(ActionEvent e) {
                   JOptionPane.showMessageDialog(null, "Left");
    }When you run that, click Load Character, then just click OK. If you press the arrow keys, corresponding alerts should come up. Now, if you rerun the program, and edit the JPasswordField in any way, then click OK, if you press the arrow keys, nothing happens. Somehow, by editing the password field, key bindings get messed up.
    Does anyone know why this happens and how to fix it?

    Eh, I hate it when this happens, but I figured it out not long after I posted this. Sorry.
    The problem was the Load Character screen was not being removed properly due to bad technique that I got from a source on Google. So the password field, which (if I understand properly) disables key bindings for security when it has the focus, or something along those lines, was not allowing the key bindings to happen.
    To see further evidence, try editing the password field, then place the cursor in the top field (that says "Default") and click OK. It works.
    Anyway, to fix the above code, I just changed the cases of TestLoadCharacterPanel.this (which didn't make any sense anyway) to this, which I didn't think would work, since it's an embedded class. But it did.
    Sorry for the pointless post.

  • Customize key bindings in AS Editor?

    I am learning Flash CS4, and I would love to be able to customize the key bindings in the ActionScript editor. Ideally I'd like to be able to use Emacs bindings (e.g. CTRL-n to go to next line, CTRL-a to go to beginning of line, etc.), but I don't see any way to set this kind of information. As powerful as I am finding Flash, I am a bit surprised at the limitations of the editor. I can't help but feel I'm missing something, but I haven't been able to successfully search for a way to customize the editor on the web. Any help would be greatly appreciated!

    Thanks for replying, kglad. I don't think "Edit -> keyboard shortcuts" is quite what I'm looking for. While it allows you to change an existing shortcut key combination, I'm not trying to run actions from the toolbar, I am trying to perform basic in-editor actions. I would like to be able to use CTRL-f to move the cursor one character forward, CTRL-p to move the cursor to the previous line, CTRL-e to move the cursor to the end of the line, etc. instead of having to use the arrow keys, or the home/end keys.
    Basically I am trying to get the editor to emulate Emacs key bindings, which I have been able to do in IDEs that I've used in my Java development. I was wondering if there was a way to do the same in Flash. Thanks!

Maybe you are looking for

  • Enhance FI_AR_4  BI datasource

    Dear Friends i have a doubts on  0fi_AR_4 is only avilable for the ODS it is not there for Cube . do we need to generate the datasource seprately for Cube. I would like to enhance the datasourcce 0FI_AR_4 . these  are all the feilds i want to add to

  • Can not use Save Image as. What happened?

    Have Firefox 3.6.12 loaded in openSuSE linux 11.3. When I try to save an image or a WebPage it may or may not work. Once it quits working, it will not work again UNTIL I delete download.sqlite and localstore.rtf I found this idea before when I search

  • Exp/imp between 10g and 9i

    Hi Gurus, In project we would like to transfer data from oracle 10g to 8i. Option selected in exp data from 10g and import to 9i. From 9i again export and import to 8i. Is there any issue between 10g and 9i and 9i to 8i ? Will normal exp file will wo

  • Installation stops

    I try to re-install Lightroom after i removed it. But the installation stops @ 42%. I get this msg; Exit Code: 7 Please see specific errors below for troubleshooting. For example,  ERROR:   -------------------------------------- Summary -------------

  • Question on sun warranty start of coverage

    hi, if my hardware warranty on a server expires on April 1 and i renew it by May 1, when would the hardware warranty starts? Arpil 1 or May 1? i'm confused because normally when we renew a service warranty, the warranty period would start at the time