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

Similar Messages

  • Hi.. Cant get Focus Area Selection in select drop down

    Hi Guys
    I cant get Focus Area Selection tool despite cc showing Photoshop CC 2014 fully updated? ..... I would be most grateful for any help
    david

    What is your exact Photoshop version?
    Could you please post a screenshot to illustrate the issue?

  • TextField get focus by mouse?

    public void actionPerformed(ActionEvent actionevent) {
    if ( textField.isFocusOwner()==true)
                   if(textField.getText().equals("Please input text") )
                        textField.setText("");
    }But TextField get focus by pressing "Enter key".
    How could i use mouse to get focus in TextField??
    Thanks a lot !!

    you can add a mouse listener to you frame so whenever someone clicks any of the mouse buttons it will give the text field the focus. Is that what you are looking for?

  • 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.

  • 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.

  • How to make a JScrollPane not getting Focus?

    How to make a JScrollPane not getting Focus?
    When i tab out from a textfield inside a scroll pane focus is going to ScrollPane .And if i press tab once more then only focus is going to other textField which is outside the scrollpane.
    For me when i press tab from a text field inside a scrollPane ,i should go to textfield out side the scroll pane.
    satish

    Hi,
    I've the same problem, that I have to double click on tab
    to step from a textfield with a scrollpane to the next textfield in my panel.
    I tried to implement a FocusListener on my JScrollPane, but without success.
    Can you tell me in detail how to implement this listener ?
    Kind regards
    Andy Kanzlers

  • Can't get focus to address bar in new tab

    I have tried everything said in previous posts and unfortunately i cant get it to focus the address bar.
    I have tried uninstalling all adons, restarted in safe mode, this should be like this automatically, but for some reason it isn't. Can i change something in about:config?
    Ty
    /A.R

    You might need to reinstall Firefox to repair program files, but first, do you want to try a different new tab page: just a blank page?
    (1) In a new tab, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (2) In the search box above the list, type or paste '''newtab''' and pause while the list is filtered
    (3) Double-click the '''browser.newtab.url''' preference and change from ''about:newtab'' to ''about:blank'' and OK that change.
    You can test immediately with Ctrl+t to see whether that makes any difference.

  • How to retain focus in Textfield

    I have one panel which contains three textfiled and one ToolBar. on clicking tool bar button certain dialog get opened.
    intially foucus remained on first textfield but when i do open the dialog with tool bar button. focus doesn't get return to first textfield even focus doesn't get back to screen.
    And my requirement is that to get focus on first textfield after closing the dialog.
    Please let me know if you have any suggestions.
    Thanks,

    yeah I need to set focus again on textfield and that is my question.you can do that using something like :jTextField.requestFocus(); I am seeking the event on which i can set the focus again please suggest.If you are using JOptionPane just add the above statement after showing dialog like JOptionPane.showInputDialog("Hello");
    jTextField.requestFocus();If you are using your own dialog, have a refrence to the textfield in the dialog and at 'windowClosing' Event use the mentioned statement.
    I think that should work....
    Thanks!

  • Select_list_from_lov, cant get the returning value

    Hi
    I try to use a apex_item.select_list_from_lov in a wizard. The LOV that I have is a dynamic list.
    everything works fine, only I cant get the return value of the selected items.
    multi select list
    htp.p(apex_item.SELECT_LIST_FROM_LOV
    ( 2,
    'MOS_ROL_OMSCHRIJVING',
    ' MULTIPLE HEIGHT=5',
    'NO',
    null,
    null,
    null,
    null,
    'NO')
    trying to see what the return values are, but got nothing.
    :p12_test := :f02;
    (p12_test is a textfield)
    any assistance would be greatly appreciated.
    Thanks
    using apex 4.0.

    >
    trying to see what the return values are, but got nothing.
    :p12_test := :f02;
    (p12_test is a textfield)
    >
    f02 is an associative array. See Referencing Arrays in the APEX API Reference for information on how to access values of items created using apex_item methods.

  • Can't get focus in JTabbedPane

    I have several tabs in a JTabbedPane. Each tabb is hotkeyed to "1","2","3", etc. The left and right arrows keys are remapped in this way:
    mainTabbPane.registerKeyboardAction (PrintHi, KeyStroke.getKeyStroke (KeyEvent.VK_LEFT, 0), JComponent.WHEN_FOCUSED);
    And I have an AbstractAction like this:
    AbstractAction PrintHi = new AbstractAction ()
    public void actionPerformed (ActionEvent e)
    System.out.print ("Hi");
    The problem is this. On each tabb I have several JTables, JLabels, JTextAreas and other stuff showing information. When I select/edit something, like a JTable, the arrow hotkeys stop function. It seems to me as the last selected JTable still has the focus and won't let it go. So when I press arrow keys, the arrow keys is directed into the JTable instead? Dont know if it so, but that is the impression I get.
    The weird thing is, the hotkeys for the different tabs works. If I press ALT + 1, the first tabb pops up. But the JTable is still selected. And the arrow keys is directed into the JTable.
    Anyone has pointers and hints?

    Ok, I apologize for not having explained my question completely. This is exactly what I am trying to do:
    When I press the arrow keys, they will print out a message. After I go to the 3rd panel and choose a combobox, I go back to the first panel and the arrow keys suddenly stop working. Why???
    (It is as if the 1st tabbpane has lost the focus, and cant get it. The focus is stuck on the JComboBox. When I switch back to 1st panel from comboboxpanel, I want the 1st panel to get focus, and hence the arrow keys will work again. When I choose the 3rd panel the arrow keys can stop work, that is ok. The important thing is that when I switch back to the first panel, the arrow key must work again. In an ideal world, the arrow keys are tied to panel 1 and panel 2. Hence, when I switch to panel 3, the arrow keys will stop work. When I choose panel 1 again, the arrow keys must work.)
    Sorry for making it difficult for you to help me. I really appreciate your effort. The thing is, I am starting a software company and am supposed to deliver the first version tomorrow monday. And everything works ok, except this CENSORED hot keys. Making me really stressed. Well, anyway I have specified the question better now. I really hope you can point me in the right direction on how to solve this problem.
    Is there a way for the shown panel to get focus? When I switch to panel 1, it gets the focus? Or should I try to tie the arrow keys to panel 1? Or should I tell the combobox to not respond to arrow keys? Which way to go?
    Please execute the program and see if it is only me having a problem?
    package test;
    import java.awt.event.ActionEvent;
    import java.awt.event.KeyEvent;
    import javax.swing.AbstractAction;
    import javax.swing.JComboBox;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.JTable;
    import javax.swing.KeyStroke;
    public class SSCCEE extends JFrame {
         private static final long serialVersionUID = 1L;
         JTabbedPane tabbpane = null;
         public static void main(String args[]) {
              new SSCCEE();
         public SSCCEE() {
              tabbpane = new JTabbedPane();
              tabbpane.insertTab("tabb 1", null, new MyTablePane(), "tooltip1", 0);
              tabbpane.setMnemonicAt(0, KeyEvent.VK_1);
              tabbpane.insertTab("tabb 2", null, new MyTablePane(), "tooltip2", 1);
              tabbpane.setMnemonicAt(1, KeyEvent.VK_2);
              tabbpane.insertTab("tabb 3", null, new MyComboboxPane(), "tooltip3", 2);
              tabbpane.setMnemonicAt(2, KeyEvent.VK_3);
              this.add(tabbpane);
              setHotKeys();
              this.pack();
              this.setVisible(true);
         private void setHotKeys() {
              AbstractAction PrintHi = new AbstractAction() {
                   private static final long serialVersionUID = 1L;
                   public void actionPerformed(ActionEvent e) {
                        System.out.print("Hi ");
              AbstractAction PrintHo = new AbstractAction() {
                   private static final long serialVersionUID = 1L;
                   public void actionPerformed(ActionEvent e) {
                        System.out.print("Ho ");
              tabbpane.registerKeyboardAction(PrintHi, KeyStroke.getKeyStroke(
                        KeyEvent.VK_LEFT, 0), JComponent.WHEN_FOCUSED);
              tabbpane.registerKeyboardAction(PrintHo, KeyStroke.getKeyStroke(
                        KeyEvent.VK_RIGHT, 0), JComponent.WHEN_FOCUSED);
    class MyComboboxPane extends JPanel {
         private static final long serialVersionUID = 1L;
         private JComboBox aCombobox = null;
         MyComboboxPane() {
              aCombobox = new JComboBox();
              aCombobox.addItem("Meow");
              aCombobox.addItem("Voff");
              this.add(aCombobox);
              aCombobox.addActionListener(new java.awt.event.ActionListener() {
                   public void actionPerformed(java.awt.event.ActionEvent e) {
                        JComboBox cb = (JComboBox) e.getSource();
                        System.out.println((String) cb.getSelectedItem());
    class MyTablePane extends JPanel {
         private static final long serialVersionUID = 1L;
         private JTable aTable = null;
         MyTablePane() {
              aTable = new JTable(
                        new String[][] { { "This", "is", "cell 13" },
                                  { "a", "Test", "cell 23" },
                                  { "cell 31", "cell 32", "cell 33" } }, new String[] {
                                  "Col 1", "Col 2", "Col 3" });
              this.add(aTable);
    }

  • My macbook pro no longer connects to my TV with the mini dvi to hdmi adapter. It was working fine now I cant get it to output to the Tv. Any ideas?

    My Macbook pro no longer outputs to my vizio led tv. It was working fine now I cant get any picture. It just says no signal. It is not the hdmi or the adapter because it works fine with my other tv. Any ideas on how to resolve this would be greatly appreciated. Please be as specific as possible. Thanks. BTW--I am using the mini dvi to hdmi adapter in case that was unclear.

    Since you say that the same connectors work on your other TV is suggests that the fault is not in the connectors but your Vizio TV.  I would check the settings on the Vizio TV.  Verify that is is set to receive HDMI input.  Perhaps you or some one else has inadvertently changed them.  Pressing the wrong buttons on a remote control device can do that.  (I am assuming no changes were made in SYSTEM PREFERENCES>DISPLAYS)
    Ciao.

  • I cant get itunes on my new laptop.  My laptop says I have to remove itunes from another computer as I can only have it on 5.  Problem is that apart from my ipad, I no longer have the others as they were either broken beyond repair or lost.  Any ideas?

    I am not good with computers.  I am trying to get my iTunes onto this new laptop but it says I am only allowed to have it on 5 computers and I must take it off one to ut it on this new laptop.  Problem is, apart from my iPad, I have lost one laptop and two have been broken beyond repair so I am unable to take it off!  Anyone any ideas?  I have tried to get iTunes support but cant get past the "date of purchase" as I can only guess when I bought my ipod (2009)

    Hang on...
    You can only authorise the songs you purchase from the iTunes Store to play on five computers.
    You can download and install iTunes (the iTunes programme) onto as many computers as you wish.
    Two different things.
    Assuming therefore, that your problem is that you have authorised five computers, but now no longer have some of them, you need to de-authorise all your computers and then re-authorise the computers you still have.
    To de-authorise your computers, go to your account in the iTunes Store and look for the Deauthorise All button.

  • I tried downloading a free app and it asked for my billing information and when i entered it, it says that there was a billing problem with a previoud purchase and i have to update it. I keep updating it and it wont let me verify it and i cant get apps

    I tried downloading a free app and it asked for my billing information and when I entered it, it said that there was a billing problem with a previous purchase and I have to update it. I keep updating it and it wont let me verify it and I cant get any apps even if they are free, and I just Deleted some apps to make room for my new upate!

    The message says: "The payment method has been denied, try another method"
    I'm living in the same country and city since I was born, so I don't think the location is the problem.
    And yes, I paid with the card a meal in Burguer King today. And nothing more.

  • How do I get my new iphone restored with my old backup? my old iphone had ios5 and the replacement phone i got has ios4 and it wont let me backup my phone because it doesnt have ios4... i cant get ios5 without restoring my iphone and backing it uo

    Basically, i need all my old stuff from my iphone 4 with ios5 onto my new iphone 4.  The new phone i received only had ios4. I went to get all my contacts and backup from my old phone onto my new phone and it wont let me because my new phone is only ios4 and my backup from my old phone was in ios5.  I cant get ios5 on my phone without creating a new backup of my new phone, which has nothing on it.  If i restore it as a new phone and backup virtually nothing from my new phone, will that get rid of all my old backup stuff from my old iphone?

    Bottom line is you CANNOT restore to a phone from a backup that has a more recent iOS which is what you're trying to do.  Just can't be done.

  • How do I connect my Mac Book Pro to a projector I have the adapter but cant get anything on the screen

    How do I connect my Mac Book Pro to a projector I have the adapter but cant get anything on the screen

    Go to your "screen settings". then chose "find screen" then you vill find the prosjector.
    this will probably fix your problem.
    if this dont works can it be something wrong with your adapter.
    hope it helps

Maybe you are looking for