Getting focus on JTextField?

I made a chat with a JApplet. In my chat i have a JTextField where users can write messages. I want to have focus on this JTextfield all the time, the user should not be allowed to get focus somewhere else. How can I do that? I tried requestFocus(); but its not making any differants. I use gridbaglayout and this is how I create my JTextfield:
beskedFelt = new JTextField(10);
c.insets = new Insets(10,0,0,0);
c.gridx = 1;
c.gridy = 2;
gridbag.setConstraints(beskedFelt, c);
contentPane.add(beskedFelt);
beskedFelt.setEditable(true);
beskedFelt.addActionListener(this);
beskedFelt.requestFocus();
thx for your time....

yesss it worked:
beskedFelt = new JTextField(10);
EventQueue.invokeLater(new Runnable() {
public void run() {
beskedFelt.requestFocus();
c.insets = new Insets(10,0,0,0);
c.gridx = 1;
c.gridy = 2;
gridbag.setConstraints(beskedFelt, c);
contentPane.add(beskedFelt);
beskedFelt.setEditable(true);
beskedFelt.addFocusListener(this);
beskedFelt.addActionListener(this);
public void focusGained(java.awt.event.FocusEvent fe)
public void focusLost(java.awt.event.FocusEvent fe)
          Object source = fe.getSource();
          if ( source == beskedFelt)
beskedFelt.requestFocus();
thx a lot ppl....

Similar Messages

  • Can't get focused a JTextField within a JTable cell

    I have a table and I placed a cell editor with a JText field on it for all cell editing,
    I want to do things when the focus is lost or gained and my app works fine when a cell is double clicked or f2 is pressed, but when a cell is selected (without double clicking) and just begin typing it produces no focus gained event.
    I tried by calling grabFocus method of that jTextField within the overriden prepareEditor method of the JTable but it doesn't get focus (doesn't even gains and loses it :s )
    Does anyone have an idea of how to force this component to grab focus?
    Thanks

    Hai,
    dont add the FocusListener to the EditorComponent.
    Try to use the JTable Functions - like this:
    import javax.swing.event.ChangeEvent;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.EventObject;
    import javax.swing.*;
    public class Test extends JFrame
         JTable table;
         JTextArea text;
         JScrollPane scroll;
         JTextField cellTextField;
         Test()
              DefaultTableModel model = new DefaultTableModel();
              cellTextField = new JTextField();
              text = new JTextArea();
              text.setEditable(false);
              scroll = new JScrollPane();
              scroll.setViewportView(text);
              table = new JTable(model){
                   @Override
                   public Component prepareEditor(TableCellEditor editor, int row, int column) {
                        text.append("Better use this to Start Edit!\n");
                        return super.prepareEditor(editor, row, column);
                   @Override
                   public void editingStopped(ChangeEvent e) {
                        text.append("Better use this to Stop Edit!\n");
                        super.editingStopped(e);
              model.addColumn("Column 1");
              model.addColumn("Column 2");          
              model.addRow(new String [] {"Cell 1", "Cell 2"});
              table.setCellSelectionEnabled( true );
              table.getColumnModel().getColumn(0).setCellEditor( new DefaultCellEditor(cellTextField));
              table.getColumnModel().getColumn(1).setCellEditor( new DefaultCellEditor(cellTextField));
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(table, BorderLayout.NORTH);
              getContentPane().add(scroll, BorderLayout.CENTER);
              setSize(300, 300);
              setVisible(true);
              setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
         public static void main(String[] args)
              new Test();
    }

  • JTextField and JTextArea don't get focus occuasionally

    I am developing a Java Swing Applet. At edit mode, JComboBox, JCheckBox, JRadioBox, and JButton work fine, but JTextField and JTextArea can't get focus occuasionally while I click them.
    Anyone has idea?
    Thanks

    Thank you Himanshu,
    but that's not exactly what my issue is. This link describes the undesired effect of ending up outisde of the player window and in the browser.
    My problem is kind of the opposite. When I launch the page in the html file I cannot use the tab key to get to any of the controls in the captivate window. I'm stuck in the browser unless I click on the captivate window. That is not acceptable if we want it accessible without using a mouse. I found a way to make it work for chrome like I stated above, but not in FF. Do you have any ideas for this?
    Thanks!
    Monique

  • JTextField gets focus NO more

    Hello,
    I have a big application running on JDK 1.4.0_03 which is running on RedHat 7.3 and sometimes it produces a very strange error.
    At some point in time (sometimes), the application refuses to give focus to JTextFields. I simply cannot click into the field any more. However, buttons still work, only JTextField cannot be used.
    Has anybody experienced anything similar?
    I am interested in any updates on this issue.
    Thank you in advance,
    G

    Rahim_From_Puniyal wrote:
    Yannix
    i post this thread at java programming forum. You reply me that "should be post at swing forum" then i post it again here you again reply my question like your previous answer.I said Next time Swing related question should be posted in the Swing forum.
    In short next time you have a new problem about swing post it in here. Simple English.
    Please don't reply if you don't have any useful answer to the question ok.
    your are not alone here at SUN developer forum. May be some give me a useful answer of my question and who is not memeber of java programming forum. that's allI think your are just one of those guys who doesn't read a post carefully.
    If you take a look at your other post I did give you an answer in reply # 1. Read Carefully.
    So before you tell me what's my problem you should read the thread carefully.
    and If you carefully read reply#1 I did state read your other thread for solution.

  • Problem with gaining focus for JTextField in JTabPane

    I have 2 tabs. The first one has a "save to file" puush button, the seccond has two textfields. When I push the save button I get a warning that not all fields in the seccond tab are filled. If I choose the first button it shows me the seccond tab and searches for the first empty field. Then it should set the focus to that field but it doesn't. Here's the code:
    void goToEmptyField() {
            tabs.setSelectedIndex(1);
            JTextField field =  (nameField.getText().length() == 0) ? nameField : actionField;
            field.requestFocusInWindow();
        }The code for determining the first empty field works fine. I'm not sure if the seccond tab gets focus or just shows up. It doesn't have the light rectangle at the tab's description. Could anybody help me please?

    seems to work OK in this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      JTabbedPane tabs;
      JTextField nameField = new JTextField(20);
      JTextField actionField = new JTextField(20);
      public Testing()
        setLocation(400,300);
        setSize(300,200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel jp1 = new JPanel();
        JButton saveBtn = new JButton("Save");
        saveBtn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            if(checkFields()) saveData();}});
        jp1.add(saveBtn);
        JPanel jp2 = new JPanel();
        jp2.add(new JLabel("Name: "));
        jp2.add(nameField);
        jp2.add(new JLabel("Action: "));
        jp2.add(actionField);
        tabs = new JTabbedPane();
        tabs.addTab("Tab 1",jp1);
        tabs.addTab("Tab 2",jp2);
        getContentPane().add(tabs);
      public boolean checkFields()
        if(nameField.getText().equals("") || actionField.getText().equals(""))
          JOptionPane.showMessageDialog(this,"field/s empty");
          goToEmptyField();
          return false;
        return true;
      public void goToEmptyField()
        tabs.setSelectedIndex(1);
        JTextField field =  (nameField.getText().length() == 0) ? nameField : actionField;
        field.requestFocusInWindow();
      public void saveData()
        JOptionPane.showMessageDialog(this,"Saving data...");
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • Why my textfield can not get focus?

    I put a textfield on the first tab of a tabbed panel. I need this textfield to get the focus when I open the first tab. I tried to use grabfocus() method in the constructor of class, but it does not work. Does anybody know why? and how can I solve it?
    Thanks!

    No, I didn't call grab/requestFocus on the event thread.
    My code is like this:
    public class GeneralPane extends JPanel {
    JPanel ltPane;
    private JTextField txtCountry;
    public GeneralPane() {
    initComponents();
    private void initComponents(){
    setLayout(new BorderLayout());
    //Add another Panel to contain Labels and Text fileds
    ltPane = new JPanel();
    FocusListener mFL = new FL();
    txtCountry = new JTextField("US", 20);
    //this listener is used to store the data in the textfield into a variable
    txtCountry.addFocusListener(mFL);
    // add the textfield into ltPane
    mUtil.insertTextPane(txtCountry,ltPane);
    //txtCountry got focus
    //txtCountry.setFocusable(true);
    ltPane.requestFocus();
    //txtCountry.requestFocusInWindow();
    Then in the main program, I create an instance of this class and then use addTab(...) function into the my tabbedPanel.
    The logic is simple, but the textfield still couldn't get focus when I open the tabbedPanel.

  • Setting Focus of JTextField

    Hello,
    I have created a JDialog subclass that has several JTextFields in it.
    When the dialog is shown, I want the first (the top-most) textfield to have the focus.
    I have tried topTextField.requestFocus() but the focus remains on anotherTextField. isRequestFocusEnabled() == true for the topTextField, and I have not called any method to request the focus for anotherTextField.
    Is there any thing trickey about this getting focus business?

    Ok,
    I just noticed that the anotherTextField that has the focus is the first component that is added to a JPanel inbedded into my JDialog, and that when I add a different textField first, it has the focus. Is this a "feature" of Swing?
    In any case, I should still be able to change the focus to anyother component.
    Any ideas would be very helpful.

  • Cant get Focus on textfield

    Hi
    I have a class extending JFrame say "MainFrame" which consist of JSplitPane say "splitPaneA"
    splitPaneA has top and bottom component.
    TopComponent is another JsplitPane say "splitPaneA-B"
    splitPaneA-B consist of a Jpanel say "B-rightPanel "as RightComponent and another JPanel as left.
    splitPaneA has bottomcoponent which is Jpanel class say "BottomPanel " extendingJPanel
    splitPaneA .setABottomComponent(new BottomPAnel());
    BottomPanel has JtoolBar say toolBar
    ToolBar has a JtextFiled say textField1 which needs to be focused as soon as bottomPanel loads.
    I tried using following in BottomPanel class
    this.setEnabled(true);
    this.setFocusable(true);
    this.setVisible(true);
    this.requestFocusInWindow();
    textField1.requestFocusInWindow()
    But textFiled never gets focused.I also tried requestFocus method.
    In class MainFrame
    FocusManager.getCurrentManager().getFocusOwner()); always returns null
    (FocusManager.getCurrentManager().getFocusedWindow()); returns null
    this.hasFocus()); returns false
    Any help is greatly appreciated.

    Thanks for your responses.
    This is my compilable,executable dummy code.I have taken out lines which are not relevant to focus issue as well as the import.Please llet me know what can be done to get the focus in textfield as soon as window loads.
    public class DummyObjectSearchPanel extends JPanel implements ActionListener
    JTextField textField1;
    JButton searchButton;
    ImageIcon searchIconIcon;
    JToolBar jToolBar1;
    private static Icon closeIcon = new ImageIcon(ObjectSearchMainPanel.class.getResource("/resources/images/close_small.gif"));
    private JButton closeButton;
    JFrame frame;
    private String newline = "\n";
    public DummyObjectSearchPanel()
    this.setLayout(new BorderLayout());
    this.setBorder(new ShadowBorder());
    textField1 = new JTextField();
    this.setEnabled(true);
    this.setFocusable(true);
    this.requestFocusInWindow();
    this.setVisible(true);
    textField1.requestFocus();
    System.out.println("has focus " + textField1.hasFocus());
    jToolBar1 = new JToolBar();
    frame = new JFrame();
    frame.setUndecorated(true);
    jbInit();
    void jbInit()
    searchButton = new JButton();
    searchButton.setText("SearchButton");
    closeButton = new JButton(closeIcon);
    ActionListener al = new ActionListener()
    public void actionPerformed(ActionEvent ae)
    textField1.requestFocusInWindow();
    textField1.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(ActionEvent e)
    searchButton_actionPerformed(e);
    jToolBar1.setBorder(null);
    jToolBar1.addSeparator();
    jToolBar1.add(closeButton);
    closeButton.setOpaque(false);
    closeButton.setMargin(new Insets(4, 4, 4, 4));
    Dimension closeBtnDimension = new Dimension(20, 20);
    closeButton.setPreferredSize(closeBtnDimension);
    closeButton.setMinimumSize(closeBtnDimension);
    closeButton.setSize(closeBtnDimension);
    closeButton.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(java.awt.event.ActionEvent evt)
    //closeButton action taken out to make code short
    jToolBar1.addSeparator();
    jToolBar1.addSeparator();
    jToolBar1.add(textField1);
    jToolBar1.addSeparator();
    jToolBar1.add(searchButton);
    jToolBar1.addSeparator();
    jToolBar1.addSeparator();
    this.add(jToolBar1);
    searchButton.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(ActionEvent e)
    searchButton_actionPerformed(e);
    textField1.requestFocusInWindow();
    void searchButton_actionPerformed(ActionEvent e)
    //searchbutton logic removed to simplify the code
    private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("New Search");
    Dimension d=new Dimension(600,100);
    frame.setSize(d);
    frame.setMinimumSize(d);
    frame.setPreferredSize(d);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    //Create and set up the content pane.
    JComponent newContentPane = new DummyObjectSearchPanel();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.getContentPane().add(new DummyObjectSearchPanel(),
    BorderLayout.CENTER);
    //Display the window.
    //frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    public void actionPerformed(ActionEvent e)
    // TODO Auto-generated method stub
    Thanks you so much

  • Avoid window getting focus after pressing a mouse button on it

    I want that a window does not get focus although I press a mouse button on it, in Windows XP.
    I have search in Microsoft help and this fact is controlled by the Operating System itself. The notification that is sent after the user presses a mouse button is WM_MOUSEACTIVATE notification. The return value of this notification indicates the behaviour of the window after the mouse down, existing 4 options: MA_ACTIVATE, MA_ACTIVATEANDEAT; MA_NOACTIVATE & MA_NOACTIVATEANDEAT. The default is the first one, but I want to change the behaviour of the window to be the the third one: MA_NOACTIVATE, that does not activate the window, and does not discard the mouse message. The function that performs this is DefWindowProc according to the MSDN Help content.
    Any help about doing this in Labview? Is there any special function in Labview that allows setting this behaviour to a window or should I use a Windows dll? In that case how can be programmed? Has anyone done it before? I'm working with Labview 8.6.1, and I haven't found anything about this. Any help will be very useful.
    Thank you very much in advance.
    David Fernández

    It is the front panel window of a VI which I don't want to get focus. I have tried to achive this with property nodes, but the problem I think that cannot be solved in this way, because is the Operative System that gives the focus to the window when pressing a mouse button before Labview does anything. You can release the focus once the window have taken it with the Front Panel window focus property node, but what I really want is to keep the focus on the old window.
    My idea is that the VI act as a background of my application, so never can be over the rest of the windows. Some of them are floating but others are standard and I don't want to use modal windows, so I cannot solve this with the Window Appearance options.
    I have also tried to discard the mouse down in the Mouse Down? event, but I doesn't work, the window continues getting the focus although does not carry on any action.
    Any suggestion?
    Thank you for your interest
    David F

  • Text box should get focus

    Hi,
              In my jsp page I have a form witho two text fields i.e input type="text"
              These two text fields get the values from scanning. Since scanning
              generates an event enter(it is going to submit the form), so after I scan
              the first value to the first text box, the second text box should get focus
              and after the ticket is scanned to the 2nd text box it should submit the
              form and the focus should return to the
              2nd text box and not the first one.
              Thanks
              Madhu
              

    I got it working
              Thanks
              Madhu
              m holur <[email protected]> wrote in message
              news:3c1f42c7$[email protected]..
              > Hi,
              >
              > It needs a java script, I am having onsumbit focus should be on the
              second
              > text box, but it is not working. I need to know what java script I should
              > use?
              >
              > Thanks
              > Madhu
              > Nils Winkler <[email protected]> wrote in message
              > news:[email protected]..
              > > This sounds like you need to use JavaScript...
              > >
              > > Nils
              > >
              > > m holur wrote:
              > > >
              > > > Hi,
              > > >
              > > > In my jsp page I have a form witho two text fields i.e input
              > type="text"
              > > > These two text fields get the values from scanning. Since scanning
              > > > generates an event enter(it is going to submit the form), so after I
              > scan
              > > > the first value to the first text box, the second text box should get
              > focus
              > > > and after the ticket is scanned to the 2nd text box it should submit
              the
              > > > form and the focus should return to the
              > > > 2nd text box and not the first one.
              > > >
              > > > Thanks
              > > > Madhu
              > >
              > > --
              > > ============================
              > > [email protected]
              >
              >
              

  • Custom TextInput itemEditor not getting focus.

    I have an AdvancedDataGrid that has a custom itemEditor on an amounts field. If I do an inline textInput itemEditor everything works fine, but if I separate out the textInput itemEditor into it's own component then when I click on the amounts column it doesn't seem to get focus. What happens is I click once and it appears like the text box has appeared, but there is not cursor, so I can't start typing my amount. I need to click a second time in the cell for the cursor to appear.
    Here are my datagrid columns:
    <datagrids:columns>
            <mx:AdvancedDataGridColumn dataField="Customer" headerText="Cust" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="Balance" headerText="Bal" editable="false"/>
            <mx:AdvancedDataGridColumn dataField="paymentAmountString" headerText="Amount"
                               editable="true" textAlign="right"
                               editorDataField="amountText" itemEditor="com.ihcfs.flex.renderers.AdvancedAmountTextInputRenderer">
            </mx:AdvancedDataGridColumn>
        </datagrids:columns>
    Here is my custom renderer/editor, I've tried both a spark TextInput and an mx:TextInput. They both have the same behavior.
    <?xml version="1.0" encoding="utf-8"?>
    <s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                      xmlns:s="library://ns.adobe.com/flex/spark"
                                      xmlns:mx="library://ns.adobe.com/flex/mx"
                                      focusEnabled="true">
        <fx:Script>
            <![CDATA[
                public var amountText:String;
            ]]>
        </fx:Script>
        <s:TextInput id="amountTextInput"
                     width="100%" height="100%"
                     textAlign="right"
                     change="amountText = amountTextInput.text;"
                     focusEnabled="true"
                     editable="true"
                     restrict="[0-9][.]"/>
    </s:MXAdvancedDataGridItemRenderer>
    If I do an inline item editor it works just fine, it's when I move it out to a reusable component that this behavior happens.
    Inline:
    <datagrids:columns>
            <mx:DataGridColumn dataField="customer" headerText="Cust"
                               editable="false" textAlign="center"/>
            <mx:DataGridColumn dataField="balance" headerText="Bal"
                               editable="false" textAlign="center"/>
            <mx:DataGridColumn dataField="paymentAmountString" headerText="Amount"
                               editable="true" editorDataField="text" textAlign="right">
                <mx:itemEditor>
                    <fx:Component>
                        <mx:TextInput width="100%" height="100%" textAlign="right"
                                      focusOut="textinput1_focusOutHandler(event)"
                                      focusIn="textinput1_focusInHandler(event)">
                            <fx:Script>
                                <![CDATA[
                                    import mx.controls.Alert;
                                    import mx.controls.Text;
                                    import mx.events.FlexEvent;
                                    import mx.formatters.CurrencyFormatter;
                                    [Bindable]
                                    private var originalAmount:Number;
                                    private var amountFormatter:CurrencyFormatter = new CurrencyFormatter();
                                    protected function textinput1_focusOutHandler(event:FocusEvent):void
                                        var e:TextEvent = new TextEvent("amountEntered", true);
                                        var textField:TextField = event.target as TextField;
                                        var newAmount:Number = 0;
                                        if(!isNaN(parseFloat(textField.text))){
                                            newAmount = parseFloat(textField.text);
                                        e.text = new String((newAmount - originalAmount) + "");
                                        dispatchEvent(e);
                                    protected function textinput1_focusInHandler(event:FocusEvent):void
                                        var textfield:TextField = event.target as TextField;
                                        if(!isNaN(parseFloat(textfield.text))){
                                            originalAmount = parseFloat(textfield.text);
                                        } else {
                                            originalAmount = 0;
                                ]]>
                            </fx:Script>
                        </mx:TextInput>
                    </fx:Component>
                </mx:itemEditor>
            </mx:DataGridColumn>
        </datagrids:columns>
    Thanks for the help!

    I attempted to do as you said using the following code:
    override public function setFocus():void{
         stage.focus = amountTextInput;
         amountTextInput.setFocus();
    I also tried adding an event handler to my renderer to capture the focus in event and try the same thing:
    <s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                      xmlns:s="library://ns.adobe.com/flex/spark"
                                      xmlns:mx="library://ns.adobe.com/flex/mx"
                                      focusEnabled="true"
                                      focusIn="mxadvanceddatagriditemrenderer1_focusInHandler(event)">
    protected function mxadvanceddatagriditemrenderer1_focusInHandler(event:FocusEvent):void
         amountTextInput.setFocus();
    Neither of these solutions work. I could just go back to using the inline code, but I'd prefer to not copy and paste that code into several different grids.
    Thanks again for the help.

  • Disabled button getting focus

    My problem is that a disabled button are getting focus, which is bad when the application are operated without a mouse.
    I made this litlte demo to illustrate the problem.
    Try pressing button no.1. This will disable button no.1 and button no.2,
    but why are button no.2 getting focus afterwards?
    * NewJFrame.java
    * Created on 29. september 2005, 16:55
    import javax.swing.*;
    * @author  Peter
    public class NewJFrame extends javax.swing.JFrame {
        /** Creates new form NewJFrame */
        public NewJFrame() {
            initComponents();
            printButtonStatus();
        private void printButtonStatus () {
            printFocus (jButton1);
            printFocus (jButton2);
            printFocus (jButton3);
            printFocus (jButton4);
         * Just debug inf.
        private void printFocus (JButton button) {
            System.out.println ("Button=<" + button.getText () + ">, Enabled=<" + button.isEnabled() + ">, Focus=<" + button.isFocusable() + ">");
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            jPanel2 = new javax.swing.JPanel();
            jButton4 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            jPanel1.add(jButton1);
            jButton2.setText("jButton2");
            jPanel1.add(jButton2);
            jButton3.setText("jButton3");
            jPanel1.add(jButton3);
            getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
            jButton4.setText("jButton1");
            jPanel2.add(jButton4);
            getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
            pack();
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:       
            jButton1.setEnabled(false);
            jButton2.setEnabled(false);
            jButton3.setEnabled(false);
            printButtonStatus();
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JButton jButton4;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        // End of variables declaration
    }

    Very courius.
    I have made a little change in your code.
    1) scenario
    Simply changing .setEnabled(false) invokation, the class works fine.
    so
    jButton2.setEnabled(false);
    jButton3.setEnabled(false);
    jButton1.setEnabled(false);
    2) scenario
    the class works fine also using your .setEnabled(false) order invokations and putting after those:
    FocusManager.getCurrentManager().focusNextComponent();
    I do not know exactly why, I suppose that is there something not properly
    syncronized in events dispaching.
    In my opinion:
    a) setEnabled(false) at last calls for setEnabled(false) of JComponent
    that fires a propertyChange event
    so:
    scenario 1)
    buttons 2 and 3 are disabled before of button1 that has the focus in
    that moment (given by a the mouse click on itself)
    When botton1.setEnabled(false) is performed buttons 2 and 3 are
    just disabled, so focus is got by button4 (that is enabled)
    scenario 2)
    button1 that has the focus (given it by the mouse click) becames
    disabled before that button2 becames disabled too.
    So, probably, when the event of PropertyChanged is fired and processed, button2.setEnabled(false) invokation has not been
    just performed and swings looks for it as a focusable component
    So, using FocusManager.getCurrentManager().focusNextComponent(),
    we force the transer focus on next focusable component.
    This is only a my suppose, looking what happens.
    Regards.
    import javax.swing.*;
    * @author Peter
    public class NewJFrame extends javax.swing.JFrame {
    /** Creates new form NewJFrame */
    public NewJFrame() {
    initComponents();
    private void printButtonStatus () {
    printFocus (jButton1);
    printFocus (jButton2);
    printFocus (jButton3);
    printFocus (jButton4);
    System.out.println("--------------------------------");
    * Just debug inf.
    private void printFocus (JButton button) {
    System.out.println ("Button=<" + button.getText () + ">, Enabled=<" + button.isEnabled() + ">, Focus=<" + button.hasFocus() + ">, Focusable=<" + button.isFocusable() + ">");
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    jPanel1 = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();
    jButton3 = new javax.swing.JButton();
    jPanel2 = new javax.swing.JPanel();
    jButton4 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jButton1.setText("jButton1");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    jPanel1.add(jButton1);
    jButton2.setText("jButton2");
    jPanel1.add(jButton2);
    jButton3.setText("jButton3");
    jPanel1.add(jButton3);
    getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
    jButton4.setText("jButton1");
    jPanel2.add(jButton4);
    getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);
    pack();
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    // I have simply change the order
    jButton2.setEnabled(false);
    jButton3.setEnabled(false);
    jButton1.setEnabled(false);
    // with this sentence the class work with original .setEnabled order
    //FocusManager.getCurrentManager().focusNextComponent();
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    printButtonStatus();
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new NewJFrame().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    // End of variables declaration
    }

  • How to prevent Cell from getting focus when I click on a cell in JTable

    Hi,
    I have a new problem which I did not have when using jdk1.3. I have a non editable JTable. Now whenever I select a row the row gets highlighted - which is ok but at the same time the cell on which I click ( to select the row ) also gets focus.
    Previously I used to extend JTable and override the isManagingFocus method to return false. But now it doesnt seem to work
    What should
    Thanks
    --J                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Well, I'm still using JDK1.3 and I don't get the behaviour you describe.
    When isManagingFocus is true then using the tab key will cause focus to move from cell to cell within the JTable and focus will never leave the JTable.
    When isManagingFocus is false then using the tab key will cause focus to move the the JTable to the next component on the JFrame.
    In both cases once focus is on the JTable an individual cell is always highlighted to indicate it has focus.
    The question is if your program only cares which row has been selected, why do you care if an individual cells appears to have focus?

  • Tab not getting focus on left-click after suspend in Windows 7 64-bit.

    When I left-click on a tab in Firefox 4 rc 2 after my pc wakes up from suspend in Windows 7 64-bit the tab is not getting focus. I have to use the hotkeys in order to move to that tab. My mouse works fine in other programs.

    I have an imac
    I have an magic pad (same thing as the touch pad on a macbook really)
    I have an usb mouse I use both in windows and osx
    if your trackpad somehow was registered as actived for some reason it would seem as if it was the mouse
    had some *** situations both in windows and osx when my cat sit on the magicpad

  • Two clicks for getting focus in h:inputtext ?

    Hello.
    I have a JSF page whose three first components are *<h:inputText ...*
    When I press Tab for get focus on the next inputText, the cursor pass to the next field and disappear. I need click mouse on the field for getting focus again. Why?
    Thank you.

    Then I don't know. It's certainly a matter of the webbrowser/client environment. All I can suggest is to test in different browsers/environments and to doublecheck all the generated HTML/JS output.

Maybe you are looking for

  • Tax code rounding rule not working in FTXP

    Dear Experts, I have configured new condition type for a new tax code to generate a seperate line item routed to a G/L account. The rounding rule in the condition type is commercial. Everything is looking proper up to this, but when I simulate an ent

  • I have a hp zd8000 how do i get past the power on coad?

    I have a hp zd8000 with a power on code how do I bypass the code to get into it my grandson put it on now we can't get into it me or him!!

  • Reason For Movement

    Dear all I have a Query regarding Stock Posting MB1C when i am Trying To post the Stock With 561 movement type its asking for Reason For Movement How to remove this or Hide this With Out Asking Please help me with Regards Pushpalas

  • Wrong track order on import

    Hi Everybody- Usually I can fix this problem but this one CD stumped me and I can't get the tracks in order on iTunes 11 ( which *****, IMHO) If I change setting to import time/date then the tracks line up fine but that changes the order of the artis

  • Create new highlight box style in Captivate 7 Video Demo to use in multiple cpvc files

    Hi, Is it possible to create and then save a new Highlight Box style that can be used in multiple projects, when editing video demos in Catpivate 7? I can Create a new style by saving, but when I open another .cpvc file it is not available and I can'