Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2007

Tip: Looking for answers? Try searching our database.

JComboBox pulldown problem

Thread view: 
Paul Hunter - 26 Jan 2007 04:19 GMT
It's been awhile since I used Swing, and I ran into an issue. I wanted to
have a pulldown text choice widget using a JComboBox with the following
code:

 String[] list = {"one", "two", "three"};
 JComboBox companyName = new JComboBox(list);
 companyName.setEditable(true);
 rootPane.add(companyName);

However, the pulldown menu does not appear when the arrow is pressed. What
am I missing?

Thanks.
Andrew Thompson - 26 Jan 2007 04:47 GMT
> It's been awhile since I used Swing, and I ran into an issue. I wanted to
> have a pulldown text choice widget using a JComboBox with the following
[quoted text clipped - 3 lines]
>   JComboBox companyName = new JComboBox(list);
>   companyName.setEditable(true);

    getContentPane().add( companyName );
    validate();

> However, the pulldown menu does not appear when the arrow is pressed. What
> am I missing?

Try the above, if that fails, I suggest
you prepare an SSCCE..
<http://www.physci.org/codes/sscce>

HTH

Andrew T.
Paul Hunter - 26 Jan 2007 05:07 GMT
One SSCCE as requested:

import java.awt.*;
import javax.swing.*;
public class test1 extends JFrame {

   public test1 () {

       super();
       setSize(200,200);

       Container rootPane = getRootPane();

       rootPane.setLayout(new FlowLayout());

       String[] list = {"one", "two", "three"};
       JComboBox box = new JComboBox(list);

       box.setEditable(true);
       rootPane.add(box);

   }

   public static void main (String[] args) {

       test1 s = new test1();

       s.run();

   }

   public void run () {

       setVisible(true);

   }
}

>> It's been awhile since I used Swing, and I ran into an issue. I wanted to
>> have a pulldown text choice widget using a JComboBox with the following
[quoted text clipped - 18 lines]
>
> Andrew T.
Andrew Thompson - 26 Jan 2007 05:33 GMT
> One SSCCE as requested:

Please refrain from top-posting.

I trimmed your SSCCE, here's my version.
<sscce>
import java.awt.*;
import javax.swing.*;

public class test1 extends JFrame {
   public test1 () {
       super();
       setSize(200,200);
       setDefaultCloseOperation(
           JFrame.EXIT_ON_CLOSE);

       // do you recall me mentioning
       // 'content pane' earlier?
       Container contentPane = getContentPane();
       contentPane.setLayout(new FlowLayout());

       String[] list = {"one", "two", "three"};
       JComboBox box = new JComboBox(list);

       box.setEditable(true);
       contentPane.add(box);
       // do you recall me mentioning
       // 'validate' earlier?
       validate();
   }

   public static void main (String[] args) {
       test1 s = new test1();
       s.setVisible(true);
   }
}
</sscce>

The drop-down values can be selected in this version.

Andrew T.
Thomas A. Russ - 29 Jan 2007 19:50 GMT
>         Container rootPane = getRootPane();
                                 ^^^^
         Container rootPane = getContentPane();
           

This is the mistake.  You want to add the component to the Frame's
contentPane, not the rootPane.

Signature

Thomas A. Russ,  USC/Information Sciences Institute



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.