Help in Changing Initial Focus in Jpanel?

HI
I have extended JPanel to create a class which has many components like JButtons etc. This class is reusable and has to be used at many places.
When I include this class in a JFrame, the focus is always with the first component of my class. But I want the initial Focus to be with another component.
I can do this by calling some method from outside my class but I do not want the user to bother with this extra function calling. Is there any way to change initial focus from within my class? I have already tried grabFocus() and requestFocus() but these methods have no effect before frame packing. Can anybody suggest some workaround?
Regards
Abhinit Kumar

You have to do it after the frame is visible. Assuming you class is not a singleton, make the call to requestFocus the last thing in the contructor.

Similar Messages

  • Change the initial focus to "message" in JOptionPane.showOptionDialog?

    JPanel panel = new JPanel (false);
    JTextArea txtArea = new JTextArea (msg, 2, 60);
    JScrollPane sPane = new JScrollPane (txtArea);
    panel.add (sPane);
    int button = JOptionPane.showOptionDialog (frame, panel, titleStr, optionType, JOptionPane.PLAIN_MESSAGE, null, null, null);
    Is there a way to make txtArea to have the initial focus?
    Thanks,
    Ben

    Hi,
    Check out this post:
    Hide the 'no data found' message
    I hope that helps.
    -Marc

  • HT5622 I need help trying to figure out why I'm not able to purchase anythi iTunes. I changed my password, that didn't help. I changed my payment type, that didn't help. It initially started when my password got disabled. Any advice?

    I need help trying to figure out why I'm not able to purchase anything on iTunes. I changed my password, that didn't help. I changed my payment type, that didn't help. It initially started when my password got disabled. Any advice?

    I need help trying to figure out why I'm not able to purchase anything on iTunes. I changed my password, that didn't help. I changed my payment type, that didn't help. It initially started when my password got disabled. Any advice?

  • Initial Focus

    I have six text boxes in a panel. How do I make the initial focus to be in the first enabled text box. And how do I make the focus to traverse in a serial order..like how it used to work with setNextFocusableComponent() in jdk1.3.
    Please help.

    Here you are (It's Christmas time ;-) )
    The following programme demonstrates a simple way of controlling the focus
    sequence when navigating with the TAB and shift-TAB keys through the components
    of a panel.
    Here we have only four textfields (tf1-tf4) in one column and two buttons (b1,
    b2) in a second column. When running the programme, the focus sequence is: tf1,
    b1, tf2, tf3, b2, tf4.
    But this is not really what we would like. We'd rather prefer to first fill the
    textfields and then choose between two different actions. So remove the comment
    slashes in
    //    panel.setFocusCycleRoot(true);
    //    panel.setFocusTraversalPolicy(new MyFocusTraversalPolicy());
    Recompile and run, and see that the sequence is now: tf1, tf2, tf3, tf4, b1, b2
    as desired.
    What has happened?
    With "panel.setFocusCycleRoot(true);" we declared our panel as the FocusCycleRoot
    which is an obligatory step. The actual FocusTraversalPolicy is defined in our
    own class MyFocusTraversalPolicy. What happens there? Not very much. The
    important thing is that it extends ContainerOrderFocusTraversalPolicy; read well
    the word "ContainerOrder..." that means the order is taken from our panel IN THE
    SEQUENCE WE ADDED OUR COMPONENTS THERE. Make a brief test in changing the order
    in the panel: Cut the line
        panel.add(tf4);
    and paste it after
        panel.add(b2);
    Compile and run. Yes, our sequence has changed to: tf1, tf2, tf3, b1, b2, tf4.
    Remains to explain the effect of the method "protected boolean accept(Component
    aComp)" in class MyFocusTraversalPolicy. Well, without the accept-method the
    focus would move in our example also to the JLabels and the JPanel itself. So the
    method makes sure that the focus rests only on components which can accept input
    or fire an action.
    import java.awt.*;
    import javax.swing.*;
    public class FocusSeqDemo
      public static void main(String args[])
      { new FocusSeqDemo();
      public FocusSeqDemo()
      { JFrame frame = new JFrame();
        frame.setSize (210,220);
        frame.setTitle ("FocusSeqDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container cp = frame.getContentPane();     
        JPanel panel = new JPanel();
        panel.setLayout(null);
    //    panel.setFocusCycleRoot(true);
    //    panel.setFocusTraversalPolicy(new MyFocusTraversalPolicy());
        JLabel l1= new JLabel("A:");
        JLabel l2= new JLabel("B:");
        JTextField tf1= new JTextField();
        JTextField tf2= new JTextField();
        JTextField tf3= new JTextField();
        JTextField tf4= new JTextField();
        JButton b1 = new JButton("action 1");
        JButton b2 = new JButton("action 2");
        Insets insets= new Insets(0,0,0,0);
        b1.setMargin(insets);
        b2.setMargin(insets);
        l1.setBounds(10,40,20,21);
        l2.setBounds(10,100,20,21);
        tf1.setBounds(30,40,50,21);
        tf2.setBounds(30,70,50,21);
        tf3.setBounds(30,100,50,21);
        tf4.setBounds(30,130,50,21);
        b1.setBounds(110,60,60,30);
        b2.setBounds(110,100,60,30);
        panel.add(l1);
        panel.add(l2);
        panel.add(tf1);
        panel.add(tf2);
        panel.add(tf3);
        panel.add(tf4);
        panel.add(b1);
        panel.add(b2);
        cp.add(panel, BorderLayout.CENTER);
        frame.setVisible(true);
        panel.getComponent(2).requestFocusInWindow(); // component 0 and 1 are the
    //                                             labels.
      class MyFocusTraversalPolicy extends ContainerOrderFocusTraversalPolicy
      { protected boolean accept(Component aComp)
        { if (aComp instanceof JTextField || aComp instanceof JButton)
                                  return super.accept(aComp);
          return false; // JLabel and JPanel.
    }

  • How to Change the Focus of a form tab?

    Hi ,
    In Oracle Apps how to do the form personalization to change the focus of the form from one tab to another tab at the time of opening of a form
    For example when I am open a form in that by default the focus of the form is showing first tab i.e. TAB1 here I need to change the focus of the form is TAB2 when ever I open a form.
    Please help is it possible in Form Personalization or not if not please suggest the alternative.
    Thanks in Advance.
    Prasanna

    Please help is it possible in Form Personalization or not if not please suggest the alternative.Forms Personalization is a feature of the Oracle Enterprise Business Suite (EBS) not Oracle Forms. Please post your question in the General EBS Discussion forum. If you have a general Forms question, by all means, ask it here! ;-)
    For information on what and how you can do something with Forms Personalization, you should review the Oracle Application Framework Personalization Guide in the Oracle Applications Documentation library.
    Craig...

  • Help centering a box in a jpanel

    hi every1,
    I need some help centering a box in a jpanel both
    horizontally and vertically.
    which layout is the correct one?
    could you post a scrap of code please?
    thanxalot
    stefano

    With the GridBagLayout you basically can do everything. Are there more components in the panel or just this box. If it's just the box, change the Layout of the panel to GridBagLayout and the anchor of the box to center. That should beeverything to do.
    Cheers
    Jonas

  • Changing initial password on CompanyPortal

    Hi experts,
    User calls the reports on the Intranet-Portal.
    I created a user just new.
    I thought by first login, system should ask to change Initial Password.
    If user make his/her first login over the Intranet portal, it does not ask to change the initial password.
    Do you know how to set up this ?
    Thanks.

    I think you would be using the same userid for all the applications in the intranet.
    if you are resetting the password, then you have to follow the same password in other applications in the intranet...
    i think, this is not practice to change/reset the password always in the intranet portal.
    I am not sure, how much feasible it is..
    Hope this would help you.

  • Prompt to change initial password

    Do you know if it is possible to have a prompt to change initial password on GDS console login?
    How can it be implemented?
    Thank you

    Hi,
    I think,  it is possible to prompt User to change initial password on login.
    Please go through [this link|http://help.sap.com/saphelp_gds20/helpdata/EN/45/1104685aa66cbfe10000000a114a6b/frameset.htm] for more details about User Management in GDS (in the "adding a new User" Section it is clearly mentioned that new user is required to change the password at first login. )
    Hope this helps.
    Regards,
    Shiv

  • Can anyone help me change the DOB on my sons profile for his apple I'd so I can setup family sharing? I originally put both ids in my name. He is 19 do it keeps saying needs my permission but no instructions in how to get that done?

    Can anyone help me change the DOB on my sons profile for his apple I'd so I can setup family sharing? I originally put both ids in my name. He is 19 do it keeps saying needs my permission but no instructions in how to get that done? His phone was stollen once last month need to get this done ASAP to prevent future headaches. Ty

    You can not change the date of birth on the account. Apple makes that clear up front when the account is created.
    The only way to "fix" this is going to be for him to create a new account with the correct information. Any apps purchased with the old one will need to be re-purchased with the new account. They can not be transferred.

  • Programati​cally change control focus to generate and Event.....​.

    I'm adding some user enhancement (anti-screw-it-up functions) to insure the desired process is executed.
    Primary question:  If I have an event that is handles by a value change in a text control, (event happens when you hit Enter or exit control with mouse) will the event also occur if you exit the control by programatically changing the focus to another control ?
    I'm going to try and set up a temp vi to test this but wanted to see if anyone had tried this and if it works or not.  My other option is to set up multiple event cases but I was hoping to use a single case to handle everything.
    A few details,  I have a test system that tests a product automatically when the product is placed in a cradle and the cradle is moved into position and activates a prox sensor.  At end of test, system waits for prox sensor to de-activate before resetting the system.
    If a unit fails, there are rework options and the unit can be retested.  When it fails, a label prints defining the failure modes and provides a failing serial number.  When the unit is retested, the failing serial number is entered into a text control. I want the re-test sequence (queued up in the Event) to occur when either 1, a failing serial number is entered or two a button is pressed (with mouse)  I'm pretty sure pressing a button would in turn automatically create the text control change event so my button can probably be a dummy button just for appearances.
    Where the hole is if the user enters a failed serial # and doesn't exit the control and then engages a pump to start the test.  I can use a 'Empty Path/String' function but the control will continue to show empty as if nothing was entered until the Enter key is pressed or the mouse is used to exit the control.
    If I can generate the event by changing the focus, then it will insure that if a failing s/n is entered, the re-test sequence occurs and if nothing exists in that field, it performs a first time test.
    A little long winded for sure but any thoughts are appreciated.
    Can't really post any simple code as this feature is in my top level vi and I have a really big app that doesn't warrant uploading.
    Doug
    Doug
    "My only wish is that I am capable of learning each and every day until my last breath."
    Solved!
    Go to Solution.

    Actually, changing the focus alone did not trigger the event but I was able to then utilize the Empty Path/String function to drive a Value(Signaling) node for the control.
    Doug
    "My only wish is that I am capable of learning each and every day until my last breath."
    Attachments:
    Event_Structure_Trials.vi ‏29 KB

  • Can someone help me change the line width of my numbers table, its not set to thin or none and its stuck on .25. its a spreadsheet i imported from excel.

    Can someone help me change the line width of my numbers table, its not set to thin or none and its stuck on pt25. its a spreadsheet i imported from excel.

    MR,
    Apparently the import wasn't a good one.
    The best option at this point might be to start a new table. Insert a new Table, Copy the old table cell range, select the first cell in the new table and Edit > Paste and Match Style. This will throw out all the old formatting. A bit of work, but a nice clean start.
    Jerry

  • Need help in changing the langauge on the Nokia570...

    Anybody can help please. I was given a brand new Nokia 5700 by my nephew from Taiwan and the langauge set is Chinese. I do not read or write chinese. Need help to change thelangauge on the phone. Any body can help.
    Thanks in advance

    Friend, I am based in China and my secretary is chinese - but nobody can figure out how to do it. I have another engineer who has the same phone has been playing around with it for 2 days and cannot get it done also. That is the reason I am getting on this site for help.
    Thanks anyways

  • I need help on changing my region from u.s to  uk

    My region changed to the u.s and I want to change it back to the uk but it won't let me because I have 32 left on my account could someone help me try remove the 32p or help me change the region

    HT2001 itunes Gift card balance?: Apple Support Communities

  • I cannot find information to help me change the orientation of a video filmed in portrait format but only able to be played back lying on its side  (landscape) instead of upright. All the rotation buttons for iPhoto are not 'engaged' when it is in video .

    I cannot find information to help me change the orientation of a video filmed in portrait format but it can only able to be played back lying on its side  (landscape) instead of upright. All the rotation buttons for iPhoto are not 'engaged' when it is in video .

    Thanks OT,
    I tried the Export function but it would not allow me to choose the option of exporting to iMovie. I think you are right about needing Quicktime Pro. I opened iMovie and imported the clip from iPhoto and with some searching found the 'cropping, rotation' mechanism. So I now have a copy in the correct orientation. I plan to import/export it back to iPhoto because I want to have a copy on my iPhone to show people and I wanted to have it available as part of a slideshow I am making in iPhoto of my recent overseas trip. It is a pain that there is no simple orientating tool for the movie clips downloaded to iPhoto with the photos from the one camera.

  • I just installed Photoshop and want to use it as the external editor.  I also have PS Elements on the computer and the only external editor I can get iPhoto to recognize is PSE.  Any help in changing the external editor to PS would be appreciated!

    I just installed Photoshop and want to use it as the external editor in iPhoto.  I also have PS Elements on the computer and the only external editor I can get iPhoto to recognize is PSE.  Any help in changing the external editor to PS would be appreciated!

    Welcome. I am using Photoshop CS5 and this works fine for me. Possibly Adobe has changed this in CS6. Hopefully, LarryHN will have further suggestions. Best.

Maybe you are looking for