Trying to give the focus at my JComboBox

Hey does somebody knows what i'm doing wrong,
i have a JFrame with a JTextField and a JComboBox, i want to give the focus on startup to the JComboBox but the form gives it to my JTextField, here is my code to ask the focus for my JComboBox
keuzeBox.addComponentListener(new ComponentAdapter(){
public void ComponentShown(ComponentEvent ex){
((JComboBox)ex.getSource()).requestFocusInWindow();
what am i doing wrong?

I'm not sure if componentShown is applicable to JFrame class (as a lightweight component). The event seems to not be fired.
Try this, as you mentioned you are displaying a JFrame, prefer to use a WindowFocusListener.
        frame.addWindowFocusListener(new WindowFocusListener() {
            public void windowGainedFocus(WindowEvent e) {
                keuzeBox.requestFocus();
            public void windowLostFocus(WindowEvent e) {
        });

Similar Messages

  • Re: trying to set the month of a JComboBox

    I am reading in from a file
    Note my problem is trying to set the month of a JComboBox.
    try
    { BufferedReader myinp;
    myinp = new BufferedReader( new FileReader("myfile2.txt"));
    while ((str = myinp.readLine()) !=null)
    StringTokenizer st = new StringTokenizer(str, "\t");
    txtfdInitials.setText(st.nextToken());
    int expireday = Integer.parseInt( st.nextToken() );
    for (int i = 0; i < 31; i++)
    if ( Integer.parseInt(days) == expireday)
    cdp.getComboDay().setSelectedIndex(expireday-1); // with days it is easy cos its int
    String expiremonth = st.nextToken();
    for (int i = 0; i < months.length; i++)
    if (months[i].equals(expiremonth) )
    //please help here
    //for exmaple if expire month is March
    // i want to do something like
    //cdp.getComboDay().setSelectedIndex(2);
    //it is easy to do with days as this is an integer but how can I do it with months.
    // please help
    myinp.close();
    catch(IOException e)
    { System.err.println("Exception: " + e.getMessage());
    System.exit(1);
    Thanks in advance

    sorry to all the experts,
    At present I can't see the wood for the trees.
    Have a lot on my plate.
    Ignore the message:
    String expiremonth = st.nextToken();
    for (int i = 0; i < months.length; i++)
    if (months.equals(expiremonth) )
    cdp.getComboMonth().setSelectedIndex(i);
    }

  • Button.requestFocus(); does not give the focus to a button...

    I have a Frame with a message (textPane) and a button, for accept the message. I want the button to be focused when I open the frame, so this will allow the user to just press one key for accepting the message without use the mouse.
    How can I acomplish this???!!!
    Thanks on advance.

    I still cannot give the focus to the button when I open the JDialog.
    My code is this:
    public class VError extends JDialog
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    JTextPane jTextPane1 = new JTextPane();
    JPanel jPanel1 = new JPanel();
    JButton jButton1 = new JButton();
    GridBagLayout gridBagLayout2 = new GridBagLayout();
    String message;
    ResourceBundle mes = ResourceBundle.getBundle("com.saincotrafico.optimus.client.resources.RError",Locale.getDefault());
    MutableAttributeSet mas;
    public VError(String message)
    this.setSize(250,150);
    this.setResizable(false);
    this.getContentPane().setBackground(UIManager.getColor("Panel.background"));
    this.setTitle(mes.getString("title"));
    this.message = message;
    try
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    private void jbInit() throws Exception
    mas=new SimpleAttributeSet();
    StyleConstants.setAlignment(mas,StyleConstants.ALIGN_CENTER);
    jTextPane1.setParagraphAttributes(mas,true);
    jTextPane1.setEditable(false);
    jTextPane1.setSelectedTextColor(Color.black);
    jTextPane1.setText("\n"+message);
    jTextPane1.setBackground(this.getBackground());
    jTextPane1.setEditable(false);
    this.getContentPane().setLayout(gridBagLayout1);
    jButton1.setSelected(true);
    jButton1.setText(mes.getString("aceptar"));
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton1_actionPerformed(e);
    jPanel1.setLayout(gridBagLayout2);
    this.getContentPane().add(jTextPane1, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0
    ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    this.getContentPane().add(jPanel1, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0
    ,GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 10, 0), 0, 0));
    jPanel1.add(jButton1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
    ,GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 157, 5, 158), 0, 0));
    this.getRootPane().setDefaultButton(jButton1);
    jButton1.requestDefaultFocus();
    jButton1.requestFocus();
    void jButton1_actionPerformed(ActionEvent e)
    this.dispose();
    }

  • How can I make firefox give the focus (the cursor) to the address bar when I open a new window - as it does when I open a new tab (to about:blank)?

    When I open a new tab using CTRL-T, the address/awesome bar has the focus.
    When I open a new window using CTRL-N, it does not.
    Can the behaviours be made consistent via setting a configuration option or key?
    Thanks in advance for any help!

    Hello wodow, please check it in [https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode#firefox:linux:fx27 safe mode], do you have the same behaviour ? DO NOT reset, select "Start in Safe Mode".
    thank you

  • Popup - how to get the focus in a specific compent

    Hi,
    I am trying to get the focus of my pop-up in the second component.
    Use case: New button in the table shows a popup to get the input from the user. There is a Undo Edit link (top-left) to discard changes, on top of the pop-up so by default the focus goes to the top left. I have input text boxes under that. And I am trying to get the focus (mouse cursor) in the first input text box rather than the undo Edit link. Any idea to implement that without using javascript ?
              <af:popup id="newPopup" contentDelivery="lazyUncached"
                        popupCanceledListener="#{commonUtils.CreatePopupCanceledListener}">
                <af:dialog id="createPopupDL" type="none"
                           title="#{viewcontrollerBundle.NEW_COURSE_PLAN_STRUCTURE_QUALIFIER_HEADER}"
                           resize="on">
                  <af:separator id="s1"/>
                  <af:panelGroupLayout id="pgl2" layout="vertical" halign="left">
                    <af:panelGroupLayout id="pgl3" layout="horizontal">
                        <!-- csc:undoEdit is a custom component to undo change
                        By default the focus is coming to this component -->
                      <csc:undoEdit id="ue1"/>
                    </af:panelGroupLayout>
                    <af:messages id="m1"/>
                    <af:spacer width="10" height="10" id="s2"/>
                    <af:panelFormLayout id="pfl1" labelAlignment="start"
                                        labelWidth="140">
                      <af:spacer width="10" height="10" id="s3"/>
                          <!-- I want to get my mouse cursor in this box -->
                          <af:inputText id="it2"
                                    label="#{bindings.QualifierCd.hints.label}"
                                    value="#{bindings.QualifierCd.inputValue}"
                                    showRequired="true"
                                    required="#{bindings.QualifierCd.hints.mandatory}"
                                    columns="#{bindings.QualifierCd.hints.displayWidth}"
                                    maximumLength="#{bindings.QualifierCd.hints.precision}"
                                    shortDesc="#{bindings.QualifierCd.hints.tooltip}"
                                    autoSubmit="true">
                        <f:validator binding="#{bindings.QualifierCd.validator}"/>
                      </af:inputText>
                    </af:panelFormLayout>
                  </af:panelGroupLayout>
                  <af:spacer width="10" height="10" id="s4"/>
                  <af:separator id="s5"/>
                  <f:facet name="buttonBar">
                    <af:group id="g2">
                      <af:panelGroupLayout id="pgl4" layout="horizontal"
                                           halign="start">
                        <af:commandButton text="#{smsCommonViewBundle.CreateBtn}"
                                          id="createCB" action="doCommit"
                                          partialSubmit="true"
                                          accessKey="#{smsCommonViewBundle.CREATE_ACCESS_KEY}">
                          <f:actionListener type="au.com.callista.sms.framework.view.lifecycle.PopupDismissActionListener"/>
                        </af:commandButton>
                        <af:spacer width="10" height="10" id="s6"/>
                        <af:commandLink text="#{smsCommonViewBundle.CANCEL_LNK}"
                                        id="cancelCL" action="doCancel"
                                        accessKey="#{smsCommonViewBundle.CANCEL_ACCESS_KEY}"
                                        immediate="true">
                          <f:actionListener type="au.com.callista.sms.framework.view.lifecycle.PopupDismissActionListener"/>
                          <af:resetActionListener/>
                        </af:commandLink>
                        <af:spacer width="400" height="10" id="s9"/>
                        <af:icon name="required" id="i1"/>
                        <af:spacer id="sp3" width="5" height="0"/>
                        <af:outputText value="#{smsCommonViewBundle.requiredLbl}"
                                       id="ot1" styleClass="requiredText"/>
                      </af:panelGroupLayout>
                    </af:group>
                  </f:facet>
                </af:dialog>
              </af:popup> Edited by: user9319679 on Sep 6, 2011 10:43 AM

    I dont think so that possible without javascript.. AFAIK
    <af:clientListener method="setFocus()" type="load"/>
          <af:resource type="javascript">
               function setFocus(event){
                 var input1 = document.getElementById('pt1:r1:3:pt1:it1::content'); // the complete id of the inputText - change it according to your jsff.. use firebug to get the proper id
                 if(input1!=null)
                 {input1.focus();
          </af:resource>

  • How to Get the focus of the textbox.

    Hi all,
    I have a problem in getting the focus of the textbox, The scenario is in this way,
    I have 3 textboxes in a window, each one should should get enabled one after the other only (i.e) Textbox2 should be enabled only after Textbox1 is filled and pressed the TAB button and Textbox3 is enabled only after Textbox2 is filled and pressed the TAB button. Textbox2 is also enabled when the cursor is in Textbox3 and SHIFT+TAB is pressed,
    I tried this with the Focus Listener but i cant able to get the cursor in the textbox. Please help in this, how to do this.
    Thanks in Advance.

    844031 wrote:
    Hi all,
    I have a problem in getting the focus of the textbox, The scenario is in this way,
    I have 3 textboxes in a window, each one should should get enabled one after the other only (i.e) Textbox2 should be enabled only after Textbox1 is filled and pressed the TAB button and Textbox3 is enabled only after Textbox2 is filled and pressed the TAB button. Textbox2 is also enabled when the cursor is in Textbox3 and SHIFT+TAB is pressed,
    I tried this with the Focus Listener but i cant able to get the cursor in the textbox. Please help in this, how to do this.
    Thanks in Advance.Hello user,
    If you are talking about 'TextBox' of javafx then please start a new thread on Javafx Category here:JavaFX 1.x and JavaFX Script [ARCHIVE]
    Thanks.,
    narayan

  • Problem giving the focus to an element

    Hi,
    I have a complex page, with lots of refresh, execute, method which change the selected row of my table from java...
    And i want, when a row of my table is selected, to automatically give the focus to the 2nd column of the selected row.
    For this in my java code, i get the id of the good column of the selected row and call this javascript function:
    function setFocusId(id) {
        var t = document.getElementById(id);
        t.focus();
    }The java code:
            ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
            service.addScript(facesContext, "setFocusId('" + inputId + "');");That works when i click on a line of my table !
    But sometimes i change the selected line from the java code, and i have to refresh my table. To refresh the table i use :
        AdfFacesContext.getCurrentInstance().addPartialTarget(this.getTable());And when i refresh the table with this, and then i call my function to give the focus to the column, that do not work, the focus is not given...
    Do Someone have an idea to solve that problem ?
    Regards,
    Trigger

    Hi Frank
    I have the good ID of the component:
            RichTable table = this.getTquest();
            FacesContext facesContext = FacesContext.getCurrentInstance();
            String tableId = table.getClientId(facesContext);
            RowKeySet rks = table.getSelectedRowKeys();
            String inputId = "";
            if (rks != null && rks.size() > 0) {
                Object rowKey2 = rks.iterator().next();
                String rowId = table.getClientRowKeyManager().getClientRowKey(facesContext, table, rowKey2);
                inputId = tableId + ":" + rowId + ":" + "otOvprCode::content";
            } else {
                System.out.println("Error");
            ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
            service.addScript(facesContext, "setFocusId('" + inputId + "');");It works, the id is always good, but the focus is not given when i refresh the table before ...
    Julien
    Edited by: Trigger on 3 août 2011 13:13

  • IPhoto says quit unexpectedly and will not open gives the same error over and over???

    Iphoto says it quit unexpectedly and keeps repeating the msg over and over it says to reopen and it tries then gives the same msg?

    i fixed the problem however i dont know how to delete my post?

  • TRYING TO GIVE LOG ON DETAILS TO SAP - PLEASE HELP

    Hi All,
    I am trying to give the Log On details to SAP so that they will have a look on our R/3 production system. Can you help me to give these details on secure area (step by step) please.
    Thanks,
    David

    To add log in information to the Secure Area of an OPen message to SAP, the message must be in status Customer Action.
    On the Message, there is a sub heading:Specification.
    This where the Short and long text of the problem is.
    Scoll down and there are two buttons.  Access Data (you want this one) and Service connection (for opening connection)
    Click Access Data, New pop up window opens, Click Display then add the entries that are required.

  • I have tried to update the itunes to the new version, and it keeps trying to download to drive E! It doesn't give me any options to change it either, does anyone have any suggestions?!

    I have tried to install the newest itunes and when its done downloading and trying to install, it tries to go to drive E, which is a disk drive. It gives no options to change it and I have tried about 6 times in the last 2 days! anyone have any suggestions?!?!

    It says:
    iTunes Installer completed
    Errors occured during installation iTunes could be configured.
    Your system has not been modified. To complete the installation, run the installer again.
    Click Finish to exit the installer.
    I dont know what to do next. Everything I try doesnt help it any. I really want to put music on my iPod but I cant!

  • I tried dowloading Skype yesterday and my Safari browser crashed.  It gives the message "Safari quit while using the librooksbas.dylib plug-in.  I trashed Skype but still have the browser problem.  I also tried logging in under guest, and no Safari.

    I tried dowloading Skype yesterday and my Safari browser crashed.  It gives the message "Safari quit while using the librooksbas.dylib plug-in.  I trashed Skype but still have the browser problem.  I also tried logging in under guest, and still
    no Safari.

    Julie --
    Backing up QuickTime's advice --
    Unless your bank's website is insecure, you're fine.  Go up to the Safari "Search" bar and type in Rapport.  You'll be amazed.  It may  "work" on PCs, but definitely not Macs.  And it's not needed for Macs.

  • My default search engine is Google and I deleted Bing. Whenever I open a new tab, Bing is displayed and it takes the focus so if I am trying to type a URL in the new tab, it is entered in the damn bing search box. HOW DO I GET RID OF THAT ACCURSED BING?

    My default search engine is Google and I deleted Bing from the Search Providers. Facebook is set as my home page. Whenever I open a new tab, a Bing search box is displayed on the page and it takes the focus so when I am trying to type a URL in the new tab, it is entered in the damn bing search box. HOW DO I GET RID OF THAT ACCURSED BING

    Swarnava, thank you very much! that did it and I am Bing-less . . . OH HAPPY DAY!! WOOHOO!!!! thank you, thank you, thank you!

  • How can I remove me credit card from my  account I already tried from iTunes but it won't give the option 2 remove it!

    How can I remove me credit card from my  account I already tried from iTunes but it won't give the option 2 remove it!

    Go to Store > View My Account > Edit Purchase Info. Then just click "No credit card" and hit Okay, and it will remove all of the info. Good luck.

  • How can I surrend the focus of Jcombobox in Jtable?

    There are a jcombobox for each row of a jtable. I can click each cell to choose some value from the item list of jcombobox.
    The problem is, when I import data into the table by changing the values of tablemodel, if some cell still hold the focus, the table won't show the new imported data for this specific cell, but keep the old one. Others cells without focus work well.
    For example, originally I choose a "Monday" from the combobox with focus. When I import new data (by clicking some button), for instance "Tuesday", the new data doesn't show in the focused cell.
    So, how can I surrend the focus of this specific cell to other components, for instance, some button?

    In your action for your button, before you update your table with the imported information do the following:
    if (myTable.isEditing())
        myTable.getCellEditor().stopCellEditing();
    }

  • HT1338 I have HP LaserJet 200 colorMFP M276nw and trying to install the driver on my mac pro; it gives me the error message that the driver is not available.

    Hi,
    I have HP LaserJet 200 colorMFP M276nw and trying to install the driver on my mac pro; it gives me the error message that the driver is not available.

    Typically this is caused by the internal list of compatible devices in the Mac being out of date.  All you should need to do is disconnect the printer from the Mac, run Apple Software Update (even if there are no updates, the list will still update), restart the Mac, connect the printer to the Mac, and add the print queue.  If that doesn't work, let me know.
    I am a printer tech for HP.

Maybe you are looking for

  • Avoid duplicate batch (batch managment)

    dear all, We are facing problem related to batch managment .we are using manual batch entry .we don't want to make duplicate entry of same batch (which have already assign to material) against any material.what is solution to avoid duplicate batch en

  • Any good visualizers for the iPad that work with iTunes?

    I have long wanted to hear my iTunes library through my home cinema system and watch the iTunes visualizer at the same time. Current Macs support mirroring on a TV via Apple TV, but mine are too old. I thought I could get around this with an iPad, bu

  • Search Bookmarks gives NO information about the FOLDER in which the bookmark is contained!!

    A sub folder containing Bookmarks has disappeared. The Search facility finds the individual Bookmarks ... however it gives NO information about the FOLDER in which the bookmarks are contained!! How can I retrieve the lost folder when the Search facil

  • Password request when refreshing pofcasts

    Getting the following message when Podcasts are refreshing To Access this site you need to log into area "idisk.mac.com" on web.mac.com It requires you to enter a User Name and password, none of my passwords work. I have never seen this before.

  • Option to collapse windows by double-click to title bar only, NOT minimize into dock?

    A double-click to a window's title bar did, in former incanations of the Mac system, result in a collapse of the window to title bar only. Currently, it seems that this option is gone? All I find results in "minimize to the dock". Is there a hidden o