How to getFocus in a ComboBox without choosing the inside data?

How to getFocus in a ComboBox without choosing the inside data? Once I clicked on the ComboBox, I couldnt get the focus unless I choose the data inside. Although I had tried with many different types listeners, but still couldnt get it. Could anyone help me???

It is easier to work with the JComboBox in 1.4 for what you want to do.
But try this and see if it works for you. I added a FocusListener to all the other components on the panel, and had them close the combo box popup list. Now, if another component previously had the focus, it would take 2 clicks to have the combo box's list pop up. It's quite round-about, but it seems to work.
I also printed a message on the console.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class ComboBoxPopupTest
   public static void main( String [] args )
      final JComboBox comboBox = new JComboBox( new Object [] { "one", "two",
                                       "three", "four" } );
      JButton button = new JButton( "huh" );
      JButton button2 = new JButton( "Yo, baby!" );
      final JPanel panel = new JPanel();
      final Runnable hidePopup =
         new Runnable()
            public void run()
               // This method is deprecated in 1.4.
               // But you won't need it in 1.4 anyway...
               Component comp = SwingUtilities.findFocusOwner(panel);
               if ( comp != null )
                  if ( comp.getClass().toString().indexOf("ComboBox") > -1 )
                     comboBox.setPopupVisible( false );
                     System.out.println( "helloooo comobox" );
         }; // end the Runnable
      FocusListener focusListener = new FocusAdapter() {
         public void focusLost( FocusEvent evt )
           SwingUtilities.invokeLater( hidePopup );
      // In Java 1.4, just add a focus listener to the combo box
      // instead of adding it to all the other components.
      button.addFocusListener( focusListener );
      button2.addFocusListener( focusListener );
      panel.add( comboBox );
      panel.add( button );
      panel.add( button2 );
      JFrame frame = new JFrame( "Hello" );
      frame.getContentPane().add( panel, BorderLayout.CENTER );
      frame.setSize( 400, 300 );
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      frame.setVisible( true );
}Tell me if that works for you.

Similar Messages

  • How can I add new games without overwriting the old ones?

    I have just purchased two new games in the itunes store and although they are showing in the library (under applications) my previously purchased games are not. In Summary under games it will not let me choose selected games only 'all games' and when I press sync warns that the existing games will be replaced. How can I add these games without deleting the older ones? Also if I did want to remove a game from my ipod how do I do it?

    hardlyquinn wrote:
    Part of the problem is that I can never sync the whole thing as I dont keep all my music in my library (it seems silly to have my enture cd collection on the computer).
    Clearly it ISN'T silly as it avoid issues like you are having right now. If you need more space, get an external hard drive. To me it is much sillier to only have your stuff on the iPod and no where else as the iPod, as a small portable player, is much more likely to be dropped, lost, damaged, stolen, forgotten somewhere, etc.
    While I am not familiar with the use of games on the iPod (I have never bought any) you can switch the iPod to manually manage and then you can add content to your iPod without losing what is already there. Perhaps it works for games as well.
    But long term, I strongly suggest you keep all your stuff in your library so if you need to (you have to perform a restore on the iPod, you lose it and buy a new one, etc.) you can very easily sync it all back to the iPod when needed.
    Good luck,
    Patrick

  • I have three iPads and one iPod and one iPhone.  How can I message between them without sending the message to all of them.  You send the message to your email address but all of them are set up und one account.

    I have three iPads and one iPod and one iPhone.  How can I message between them without sending the message to all of them.  You send the message to your email address but all of them are set up under one account.

    You can have a different receiving email in the Messages app on each device : Settings > Messages > Receive At . I'm not sure that there is a different way to have the message only go to one device.

  • I want to download an audiobook, but my daughter has a giftcard credit on the account. How can I download my audiobook without using the money from her giftcard?

    I want to download an audiobook, but my daughter has a gift card on the account.  How can I download my audiobook without using the money from her gift card?

    go directly to your ibook app. and you're going to find it. it's only with ibooks app.
    best
    Olivier
    <Edited by Host>

  • How can i restore old backup without deleting my existing data

    how can i restore old backup without deleting my existing data. unfortunately i have deleted few of my old photos and restored them from my old backup. i got the deleted photos but lost my recent data and photos. how can i get those too.

    You cannot. However, if your back up is through iTunes on your computer and you do an internet search for something like "iPhone BackUpExtractor", I believe there is software that will help you access the SQL database that is your back up. You may be able to pull out what you need.
    Once you restore from a back up, any data that was on the phone is gone.

  • How can i print an email without printing the attachment?

    I just got my new macbook pro retina display.  I am using Mac mail and want to know how I can print an email without printing the attachement.  Any suggestions and solutions would be appreciated.

    Thank you for your suggestion.  But when I receive an email that has an attachment (shown by paperclip symbol) The email opens and shows the attachment(jpg picture) at the end of the email so when I go to print - the email pops up with the picture already opened inside the body of the email.  Can not figure out why this happens in mac mail.  when i used outlook in windows only email would show.  in order to see attachment you had to click on paperclip and only then would the attachment (picture apprear).
    Any other suggestions that I may could try would be appreciated. Thank you!  Gabriela

  • In disk utility, it shows that my external hard drive is somehow unmounted and I can't access it in finder or repair it in Disk Utility. How can I get this working without losing my important data?

    In disk utility, it shows that my external hard drive is somehow unmounted and I can't access it in finder or repair it in Disk Utility. How can I get this working without losing my important data?
    Thank you!

    When you erased the disk did you select Mac OS Extended Journaled as the format option?

  • I mounted my external hard drive to a pc and now I don't have edit or write permissions on my Mac (read only). How do I get them back without erasing the drive?

    Hello all, I am a photographer and have my portfolio, edited and raw images backed up on a Seagate Free Agent External Hardrive. I mounted my external hard drive to a pc recently and now I don't have edit or write permissions to it on my Mac (read only). How do I get them back without erasing the drive and loosing my valuable work?

    If you re-format it you will lose all the data on it!!!!! So make sure you have backed up the drive or moved all the data on it to another external HD or the internal HD on your iMac.
    Below is an Apple Advice letter that explains how to format an external HD, it's written for Aperture but you can use the instructions to formate any external HD.
    http://support.apple.com/kb/HT3509

  • How do I test a scenario without getting the other party involved

    Hi,
    How do I test a scenario without getting the other party involved?
    I have created a scenario to receive information from an external system (Remedy), processing through a SoapAdapter into SAP to create a service order. How can I send a sample of information in order for me to test my scenario without asking the Remedy people to transmit data all the time?
    Thanks in advance,
    Leanne

    hi Leanne,
    have a look at my weblog:
    /people/michal.krawczyk2/blog/2005/08/25/xi-sending-a-message-without-the-use-of-an-adapter-not-possible
    it shows how to use the test tab from RWB
    to send test messages
    Regards,
    michal

  • HT4113 how to unlock an ipod touch without knowing the password

    how to unlock an ipod touch without knowing the password

    Connect the iPod to your computer and restore via iTunes. Place the iPod in Recovery mode if necessary to allow the restore.

  • How to launch a function/procedure without suspending the parent process?

    Hi everybody,
    I would like to know if I can define something as follows in PLSQL:
    procedure master
    begin
    call a procedure_child;
    End master;
    I would like that the procedure master does not suspend the execution and wait that the procedure_child finishes in order to resume the executions with the further code.
    Thanks a lot in advanced
    Tomeu

    In the future, please stick to posting in a single forum.
    Re: How to launch a function/procedure without suspending the parent process?

  • How can i run external application without specifying the full path?

    for example, ms word executable file is winword.exe, but in java i am using the following command:
    Runtime.getRuntime().exec("\"C:\\Program Files\\Microsoft Office\\Office10\\winword.exe\");
    the thing is, i dont know where ms word is installed on every machine, so rather than making an assumption, do you know how i can run ms word without specifying the full path?
    thanks

    1) You could ask the user to tell you where it's at (and remember for next time)
    2) You could do a file search for it (and remember it for next time)

  • Hi. We have two iphones and one Itunes account. How do back up each one without getting the others contacts

    Hi. We have two iphones and one Itunes account. How do back up each one without getting the others contacts and without syncing each phone to each other?

    Welcome to the Apple community.
    Ideally you should each have your own iCloud account, providing you with your own contacts, calendars etc, not doing so will result in exactly what you have experienced. The contacts have likely been lost due to the options you have chosen at the login stage on each device.
    Unless you have the missing contacts in a backup file, they won't be recoverable unfortunately. You can add them manually to the contracts that already exist and continue to share the iCloud account if you wish, but I suggest that you each have your own iCloud account.
    Note, you can each have your own iCloud account, but continue to share an iTunes account for purchases of apps, books, music, TV shows etc etc.

  • Everything on all the webpages are so small, and only take up half the screen. How can I make it bigger, without changing the settings on my computer and by that change the size of everything on my computer.

    Everything on all the webpages are so small, and only take up half the screen. How can I make it bigger, without changing the settings on my computer and by that change the size of everything on my computer.

    The Firefox [https://support.mozilla.com/en-US/kb/Page+Zoom Page Zoom] feature does a domain by domain level of saving the users preferred zoom level settings, there is no default Page Zoom level setting in Firefox, as with some other browsers.
    Try the Default FullZoom Level extension: <br />
    https://addons.mozilla.org/en-US/firefox/addon/6965
    Or the NoSquint extension: <br />
    https://addons.mozilla.org/en-US/firefox/addon/2592/

  • HT201240 I've forgotten my administrator password and can't download software. can anyone advise how to reset a new password without having the original?

    I've forgotten my administrator password and can't download software. can anyone advise how to reset a new password without having the original?

    Forgot Your Account Password
    For Snow Leopard and earlier
         Mac OS X 10.6- If you forget your administrator password
    For Lion/Mountain Lion
        Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
         When the menubar appears select Terminal from the Utilities menu.
         Enter resetpassword at the prompt and press RETURN. Follow
         instructions in the dialog window that will appear.
         Or see Reset a Mac OS X 10.7 Lion Password and
         OS X Lion- Apple ID can be used to reset your user account password.
    If you are unable to boot from an installer DVD:
    (these will only work on Leopard or earlier)
      1. Boot to Safe Mode by restarting and after the chime press and hold down
          the COMMAND-S keys until a black screen with white type appears.
      2. At the prompt, type the following commands pressing return after each
          command line:
         /sbin/fsck -yf
         If you do not receive a "Filesystem OK" message then repeat this command
         until you do.  If after seven tries you still do not receive a "Filesystem OK"
         message, then the system is corrupted and needs to be reinstalled.
         mount -uw /
         cd /private/var/db/netinfo
         mv local.nidb local.old
         rm ../.AppleSetupDone
         shutdown -r now
    The second-to-last command above will cause OS X to think that the operating system is newly installed, and when the new owner starts up the computer it will send him/her to the startup wizard where he/she can start a new user without reinstalling.
    This last method does not actually change a password. It simply removes the user accounts and lets you create an initial admin account as if the computer were new out of the box.
    Reset Admin Password Using The Terminal
    You can reset the password by printing out (or writing down) and carefully following these steps.
    First, find the short name of the admin user on the machine. The easiest way of doing this is by looking at what the directory is called in the Users folder.
    Now, start in Single-user Mode. It should boot into a command line.
    Enter these exact lines. Press RETURN after each.
    mount -uw /
    ifconfig lo0 up
    cd /var/db/netinfo
    netinfod -s local
    Now you'll need that short name. Enter "passwd", a space, and the short name of the admin. For example, if the admin was rather prosaically called "imadmin", you would enter "passwd imadmin".
    The computer will now prompt you to change the password for "lmadmin" (or whatever the short name was). Go ahead and enter a new password.
    Now, enter:
    sync
    reboot
    and the machine will reboot. The admin password should now be changed.

Maybe you are looking for