JButton gains focus when Hitting tab key but hitting Enter has no effect.

Hi,
I have a program that has two buttons. When pressed, using the mouse, the buttons text appears in the middle of the screen. I have NOT alerted the focus subsystem. Thus when I press the tab key the buttons are highlighted in turn, to indicate that they currently have focus. However if I press enter the buttons actions (to update the middle of the screen with it's text) does not get activated.
I am using 1.4.2 on a Windows machine.
any help on this would be much appreciated !!
The code is as follows:
package com.logicacmg.skynet.tms.mmi.ui;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Container;
public class Test implements ActionListener
JButton bTwo = new JButton("button 2");
JButton b = new JButton("button 1");
JLabel label = new JLabel(" ");
/** Creates a new instance of Test */
public Test()
JFrame frame = new JFrame();
//Create a panel to hold the MMI screens.
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
b.addActionListener(this);
bTwo.addActionListener(this);
mainPanel.add(b, BorderLayout.WEST);
mainPanel.add(bTwo, BorderLayout.EAST);
mainPanel.add(label, BorderLayout.CENTER);
//add the main panel which contains the screens and the status bar
//to this frame.
Container contentPane = frame.getContentPane();
     contentPane.add(mainPanel, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
public static void main(String [] args)
new Test();
public void actionPerformed(ActionEvent e)
JButton aButton = (JButton)e.getSource();
if(aButton == b)
label.setText("one");
else if(aButton == bTwo)
label.setText("Two");

Which plaf are you using? Because when I switch to the windows plaf, the behavior is what you describe.
Demo:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class X {
    public static void main(String[] args) {
        final JFrame f = new JFrame("button focus");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ActionListener al = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                System.out.println(evt.getActionCommand());
        Container cp = f.getContentPane();
        cp.setLayout(new FlowLayout());
        for(int i=0; i<3; ++i) {
            JButton btn = new JButton("Button " + i);
            btn.addActionListener(al);
            cp.add(btn);
            if (i == 1)
                f.getRootPane().setDefaultButton(btn);
        final JCheckBox laf = new JCheckBox("platform plaf");
        laf.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evt) {
                String cls = laf.isSelected() ? UIManager.getSystemLookAndFeelClassName() :
                  UIManager.getCrossPlatformLookAndFeelClassName();
                try {
                    UIManager.setLookAndFeel(cls);
                    SwingUtilities.updateComponentTreeUI(f);
                } catch (Exception e) {
                    e.printStackTrace();
        cp.add(laf);
        f.pack();
        f.setVisible(true);
}

Similar Messages

  • Focusing JLable on Tab key..

    Hi All,
    I have a JFrame that has four text fields and two labels.
    basically they are with save and close images acting as the button
    for me.
    Now my problem is when I press the tab key, the focus transverse
    in all four text fields, but it never comes on JLables.
    Can anybody tell me how to achieve this.
    Hoping for a favorable response
    Kind Regards
    Chetan Chandarana

    Just a guess..
    label.setFocusable(true);

  • How to determine the positioning order when using tab key?

    Hallo,
    in my jspx-page i want to define the order which the cursor jumps when the user is using the tab key.
    i don't know how to? in html there i can use tabindex. which way i must go?
    Any help is appreciated.

    I found that tabindex is not applicable. But i think it is an important point for better handling.
    Is there no easy way to do it?

  • Moowing focus with the tab key (swing)

    Hi. I have a JFrame with 4 text areas in. I want to be able to "hop" to the next text area by pressing the tab key. Most internet pages says this is default, but when I press tab, I get a tab space inside the text area I'm in.. Any ideas on how to do this? (i use Java 1.5)

    HashSet focusForward = new HashSet();
    HashSet focusBackward = new HashSet();
    focusForward.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,0));
    focusBackward.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB,InputEvent.SHIFT_DOWN_MASK));
        myTextArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,focusForward);
    myTextArea.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,focusBackward);

  • Moving the Focus with the TAB key in a JTextArea Component

    Dear Friends,
    I have exhausted all options of moving focus from JTextArea to next component. I have also tried all suggestions available in this forum. But i'm not able to solve my problem. Can any one help me.
    Thanx in advance.

    I had the same problem before. Here is what i did.
    JTextArea txtArea = new JTextArea(2,15);
    Set forwardTraversalKeys = new HashSet();     
    forwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));          
    txtArea.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,forwardTraversalKeys);          
    Set backwardTraversalKeys = new HashSet();          
    backwardTraversalKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));          
    txtArea.setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backwardTraversalKeys);
    JScrollPane scrollPane = new JScrollPane(
         txtArea,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // the scrollbar of the JScrollPane is focusable that's why it requires
    // another TAB key to transfer the focus.
    scrollPane.getVerticalScrollBar().setFocusable(false);

  • Highlight appears over rewind button when using Tab key

    I am using Captivate 4 and publishing with Actionscript 3.  When the user enters text, they can use the tab key as a shortcut key to move to the next field.  However, when they use the tab key, a highlight appears over the rewind key in the control bar.  I have tried the no_yellow_tab widget and that did not work with captivate 4/actionscript 3.  I also tried adding so.addParam("seamlesstabbing", "false"); to the html and this did nothing as well.  Any ideas?
    Thank you,
    Claudia

    Hi there
    You might try inserting a Click Box object at the top of your timeline. Configure it to do nothing if clicked and so there is no visible indication.
    I've seen it before where focus shifts instead to the hidden object and prevents it from reaching the playback controls. My thought is that after Tab is pressed, focus will then be placed on the hidden Click Box which, of course, the user will not see and will do nothing if they click.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Hitting tab key skips checkboxes, buttons, etc.

    This is my first Mac, so I'm still getting used to the UI, I was hoping someone cold help shed some light on this. When I use the tab key in any application to skip to the next field, it totally ignores the checkboxes and buttons. Is there some way around this, or does Mac OS just not allow you to tab to the checkboxes/buttons?

    in system preferences - keyboard & mouse - Keyboard Shortcuts there's an option at the bottom for altering Tab function between 'text boxes & lists' and 'all controls' .
    ctrl-F7 makes the switch w/o needing to go to sys prefs.
    I think(?) option-Tab enables the 'other' option while option is held; even if set one way.

  • JTabbedPane loosing focus when switching tabs

    When there are tiered JTabbedPanes and focus in one of the children and the tabbed is switched focus will go to the first component in the frame.
    Is there a work around to keep the focus at least on the jtabbedpane?
    Is this a know bug? anyone heard of this before?
    Googling: JTabbedPane focus didn't bring up anything helpful... is there something else I should be searching under?
    Here is an example:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    public class TabPaneTest extends JFrame {
        public TabPaneTest() {
            JButton focusStealer = new JButton("Look at me!");
            focusStealer.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent e) {
                    System.out.println("I TOOK FOCUS! W00t!");
                public void focusLost(FocusEvent e) {
                    //To change body of implemented methods use File | Settings | File Templates.
            JTabbedPane tabbedPane = createTabbedPane(0);
            getContentPane().add(focusStealer, BorderLayout.NORTH);
            getContentPane().add(tabbedPane, BorderLayout.CENTER);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(300, 200);
            setLocation(400, 200);
            setVisible(true);
        private JTabbedPane createTabbedPane(int deep) {
            deep++;
            JTabbedPane tabs = new JTabbedPane();
            for (int i = 0; i < 4; i++) {
                if (deep < 4) {
                    tabs.add(i + ":" + deep + " - Focus", createTabbedPane(deep));
                } else {
                    tabs.add(i + ":" + deep + " - Focus", new JTextField());
            return tabs;
        public static void main(String[] args) {
            new TabPaneTest();
    }

    When there are tiered JTabbedPanes and focus in one of the children and the tabbed is switched focus will go to the first component in the frame.
    Is there a work around to keep the focus at least on the jtabbedpane?
    Is this a know bug? anyone heard of this before?
    Googling: JTabbedPane focus didn't bring up anything helpful... is there something else I should be searching under?
    Here is an example:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    public class TabPaneTest extends JFrame {
        public TabPaneTest() {
            JButton focusStealer = new JButton("Look at me!");
            focusStealer.addFocusListener(new FocusListener() {
                public void focusGained(FocusEvent e) {
                    System.out.println("I TOOK FOCUS! W00t!");
                public void focusLost(FocusEvent e) {
                    //To change body of implemented methods use File | Settings | File Templates.
            JTabbedPane tabbedPane = createTabbedPane(0);
            getContentPane().add(focusStealer, BorderLayout.NORTH);
            getContentPane().add(tabbedPane, BorderLayout.CENTER);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(300, 200);
            setLocation(400, 200);
            setVisible(true);
        private JTabbedPane createTabbedPane(int deep) {
            deep++;
            JTabbedPane tabs = new JTabbedPane();
            for (int i = 0; i < 4; i++) {
                if (deep < 4) {
                    tabs.add(i + ":" + deep + " - Focus", createTabbedPane(deep));
                } else {
                    tabs.add(i + ":" + deep + " - Focus", new JTextField());
            return tabs;
        public static void main(String[] args) {
            new TabPaneTest();
    }

  • Downloading CS6 Master Suite when having a key but no media

    I purchased a license for CS6 master suite thorugh my school. The directions given by my school was to download the trial version and then activate it using the key. That was fine until last weekend when I had to reformat my laptop. I have no media for this software. It was purchased on 1/19/13 not even 6 months. Anyway, the trial download for CS6 master suite is gone. I have read some of the forums and they route people to a Prodesigns tool website. I have followed the directions given there, and no success. I kepp on getting a  denied access. I have tried to do so in both chrome and internet explorer, but I have no luck.
    How can I download this software again?
    Thank you

    Prodesigns tool website. I have followed the directions given there, and no success. I kepp on getting a  denied access.
    You'll get a Denied Access error if you do not carefully follow the Very Important Instructions on the prodesigntools page before you click the download link.
    Most people seem to stumble on steps 2 and/or 3.
    I just tried downloading CS6 Master Collection from prodesigntools.com and it worked fine for me in Chrome and Firefox.

  • Graphics card issue: works fine when in boot camp but OSX it has issues.

    Hey guys. I've had my Macbook pro since 2011 and it used to run games pretty well on it but now it struggles really bad. If I boot into BOOTCAMP and play games it still works fine . Do you guys know what could be the cause of this issue and how do I resolve this?

    Already tried that before. I don't even have any software firewall currently active, and the hardware firewall in my router does not block individual applications. It blocks ports instead, by IP address. My Avast AV software does not have anything that blocks applications either, since there is no firewall aspect to it, just the anti-virus software. Likewise, my Spybot S&D has no blocking capability either.
    I followed all the steps in the article titled "Firefox can't load websites but other browsers can" when I tried installing v24 and v25 last night, which included the steps from the article you posted above with regards to firewalls, as well as changing proxy settings, disabling IPv6 and DNS Prefetching, and resetting Firefox defaults from the troubleshooting page, which blew out all my settings, and still nothing.
    I had tried all the steps I could find on these pages, which is why I thought I would post my issue, since I had run out of ideas. I even took a look at the info about the issue some people are getting where it works for them only if they are moving their mouse, but even moving my mouse didn't get any results for me.

  • Tab key (to toggle panels) has stopped working.

    This happens once in awhile and I haven't figured out if I've inadvertantly disabled it or if it's a bug. Closing and reopening AICS 4 does not fix it, nor does a total restart. I AM using a custom "Workplace" if that makes any difference.
    Ray
    PS… switched to a standard workspace and Tab still does not hide panels.

    AICS 4, Mac OSX 10.6.4. Have not trashed prefs. I will try that once I've finished a rush job.
    Thanks

  • ACI modification with Plug-in, but Problem, it has no effect.

    I wrote Plug-in which modifies some entries' ACI attribute according to client's certain request.
    My Plug-in works well, ACI is updated well, and updated ACI Syntax is legal.
    But, the updated ACI does not effect on Access controll.
    It effects nothing
    until the ldap server is restarted
    or it(the ACI updated by Plug-in) is re-edited via iPlanet console.
    following is real ACI example and more detailed .
    1. After client`s certain request (modifying some entry), following ACI value is added to an entry by plug-in. ( My fellow wrote the plug-in)
    (targetfilter = "(ssoUsPathId=mt04-01)")
    (targetattr = "*")
    (version 3.0; acl "SLAPI-generated Permissions"; allow (all)
    (userdn = "ldap:///uid=ga,ou=user,o=ssoroot??sub?(ssoAccessAllowed=TRUE)");)
    2. But the user "ldap:///uid=ga,ou=user,o=ssoroot??sub?(ssoAccessAllowed=TRUE)");)" has no Access
    to the entries allowed by the updated ACI.
    3. Two mothods make it effect the updated ACI, but it's manual and impractical.
    3.1. one : restart the iplanet ldap server 5.0.
    3.2. two : edit & save the ACI updated by plug-in, through the iPlanet Console 5.0.
         but, "edit & save" only does add meaningless space the ACI.
         following is the same case before and after "edit & save"
    (targetfilter ...) (...) (...) : before
    (targetfilter ...) _(...) (...) : after
    ("_" means space)
         Difference between before & after is only meaningless space.
         Before & after has same meaning in ACI Syntax.
    There is no difference between step 2. and step 3.2. in ACI meaning & syntax.
    4. what can i do for resolving this problem?
         Thanks in advance.

    If you want to ensure the ACI has that value you need to write a pre-op plugin which only makes this change when the aci is changed. Aci's are cached and the only way to trigger a re-cache is a modify operation involving the aci attribute.

  • JTextArea not gaining focus

    I have a tabbed pane consisting of 2 JPanels. Each panel has a text area (within a scrollpane) on both.
    All I want is for the text area to gain focus when its tab has been clicked.
    I've tried adding a changelistener to the tabbedpane:
            tabbedPane.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    if (tabbedPane.getSelectedIndex() == 0) {
                        textArea1.requestFocus();
                    else {
                        textArea2.requestFocus();
            });but the textareas don't get focus. They do when I press <TAB> but this isn't much use.
    Does anyone have any ideas how I can get the textareas to gain focus?

    import javax.swing.*;
    import javax.swing.event.ChangeListener;
    import javax.swing.event.ChangeEvent;
    import java.awt.*;
    public class TestFocusTabbedPane extends JTabbedPane {
         private JTextArea theFirstTextArea;
         private JTextArea theSecondTextArea;
         public TestFocusTabbedPane() {
              super();
              JPanel tabPanel = new JPanel(new BorderLayout());
              tabPanel.add(new JButton("just for test"), BorderLayout.NORTH);
              theFirstTextArea = new JTextArea();
              theFirstTextArea.setFocusable(true);
              tabPanel.add(new JScrollPane(theFirstTextArea), BorderLayout.CENTER);
              addTab("first", tabPanel);
              tabPanel = new JPanel(new BorderLayout());
              tabPanel.add(new JButton("just for test"), BorderLayout.NORTH);
              theSecondTextArea = new JTextArea();
              theSecondTextArea.setFocusable(true);
              tabPanel.add(new JScrollPane(theSecondTextArea), BorderLayout.CENTER);
              addTab("second", tabPanel);
              addChangeListener(new ChangeListener() {
                   public void stateChanged(ChangeEvent e) {
                        int index = getSelectedIndex();
                        if (index == 0) {
                             theFirstTextArea.requestFocus();
                        } else {
                             theSecondTextArea.requestFocus();
         public static void main(String[] args) {
              final JFrame frame = new JFrame(TestPressedButton.class.getName());
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.getContentPane().add(new TestFocusTabbedPane());
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        frame.pack();
                        frame.show();
    }This seems to work. I added the JButton just to show that it doesn't get the focus

  • Why can't I type in text fields without first hitting the Tab Key?

    I have Version 32.0.1700.77 running on a Mac. This problem started with Firefox a little while back and no amount of updates or uninstalling/reinstalling has fixed it. And therefore I have switched to Chrome.
    When using Firefox, any text field, including the address bar, will not allow me to type into it. I will get a BONK sound. Once I hit the Tab Key, I can begin typing. But if I stop typing and click any other area, then come back to the text field, I must again hit the Tab Key. Or if I want to edit the text field, I can highlight a word, but for it to delete, I have to hit the tab Key then hit Delete.
    Why is it doing this?

    hello, please try to [[Reset Firefox – easily fix most problems|reset firefox]] and see if this can address the issue...

  • Popup of JComboBox shows on mouseclick but disappears on tab-key

    Hi everybody, I have a DefaultCellEditor with a ComboBox and I want the popup to be visible on focus, so I overwrite the changeSelection method of the JTable as follows:
    public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
                super.changeSelection(rowIndex, columnIndex, toggle, extend);
                super.editCellAt(rowIndex, columnIndex);
    } else if (getEditorComponent() instanceof JComboBox) {
                    JComboBox editor = (JComboBox)(getEditorComponent());
                    editor.requestFocusInWindow();
                    editor.showPopup();
                }This behaves like I want it to on mouseclicks. On Tab focus the popup is shown as long as I hold the tab key but disappears again after. What does the release of the Tab key does what the mouse button doesn't and can I change it?
    thanks for aswers

    Classic case of file naming.
    iOS is case-sensitive and requires the name of the file be exactly the same as that used in your code.
    MyImage01.png is not the same as myIMAGE01.PNG
    OS X, and thus the simulator, is not case-sensitive.

Maybe you are looking for

  • Itunes could not check for an update to the carrier settings for your iphone. An unknown error occur (-50)

    Have problem with "Check for Updates" for iTunes or accessing iTunes stores.  Called Apple support locally in Singapore who couldnt help resolve the problem and was directed to helpdesk in Norway but after hours on the phone, they still could not sol

  • Log error while clearing inventory document through Li20

    HI All, I have the following issue while creaing inventory document in warehouse level through LI20. System says Available quantity of material is ZERO while clearing stock in WM. We are able to count this inventory document and status of inventory d

  • Thunderbolt to FireWire adapters

    What is the actual release date of Thunderbolt to FireWire adapters in July? I understand they say it's in July but now we are down to the final weeks and still no word on the actual release "day". I just bought a MacBook Pro with Retina display as w

  • PO part no and SKU part number different

    I have the Material part no on which we want to do Procurement. and put the material in stock and do valuation. Then I have the Vendors part number which is different than above part no. Mans if my material code is ABC then Vendors code may be DFG. I

  • Activesync doesn't sync

    Just got two new Treo 800w phones. On WinXP Home, ActiveSync 4.5 is loaded to two profiles. I can't sync either phone in either of the profiles via USB connection. I was able to connect the phones (individually) and kick off synchronizing Mail, Calen