Solved

JComboBox disappearing drop down button

Posted on 1998-05-25
5
551 Views
Last Modified: 2012-05-04
Hi,

I'm using the Swing1.02 JComboBox component setting its 'Editable' data member to true ('setEditable(true)').
As a result the user can insert free text, but whenever he's writing, the drop down button on the right is disappearing. After changing the focus to some other component the button re-appears.

I checked the SwingSet demo and over there the JComboBox appears as it should (always).
From the sources I could not find any differences between the SwingSet way of JComboBox usage and mine.

If anyone knows how I may ask the JComboBox component to show the dropdown button always, I would most appriciate it.

Thanks in advance,
Guy Loewy.
Optimal Technologies, Inc.
0
Comment
Question by:optimal
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:fontaine
Comment Utility
Could you post a piece of code showing the unexpected behaviour?
0
 

Author Comment

by:optimal
Comment Utility
The following code is part of "SearchPanel" class which extends JPanel, and
it appears in the constructor of that class.

        // treeSearch JComboBox:
        treeSearchCB = new JComboBox();
        treeSearchCB.setEditable(true);
        treeSearchCB.setBounds(45, 70, 120, 20);
        this.add(treeSearchCB);


0
 
LVL 5

Expert Comment

by:fontaine
Comment Utility
I can't reproduce your problem (I used the Metal L&F). However, if I had to make just a single try, it would be to change the way the layout is done. You should indeed use the layout managers instead of placing yourself the components. When you are placing yourself a component, you are in fact making strong hypothesis on the way it will be displayed. For example, if you switch the L&F to something else than what you are currently using, your interface will probably be in a bad shape...
0
 
LVL 1

Accepted Solution

by:
dufort earned 300 total points
Comment Utility
I strongly agree with fontaine. Do expect strange behavior when you place components on frames by yourself. If you need tips on layout managers, take a look at the Java Tutorial at Sun:
http://java.sun.com/docs/books/tutorial/ui/layout/index.html

By the way, may I suggest that you use getContentPane().add(treeSearchCB) instead of this.add(treeSearchCB). Maybe it could help in the repainting behaviour of your combo box... In Swing, NEVER EVER place components directly on JFrames, because there are several "panes" between the frame and your eyes.

If this is a good answer, give me feedback, and I will repost it as an "Answer" (for the points, of course  ;-)  ).

0
 
LVL 1

Expert Comment

by:dufort
Comment Utility
Hi Dufort,

I'm not adding the JComboBox directly to a JFrame. The Object is added to a JPanel component, therefor, I can't use "getContentPane()" which is a JFrame/JApplet method. The JPanel itself is being added using the "getContentPane().add(MyJPanel)" to the JApplet.

Second, I do understand the importence of layout managers, but since the JPanel to which I add the JComboBox is really a complex one, I preferred to use "null" layout. In JBuilder there is a XYLayout that acts the same way a "null" layout does but that makes my applet too big (and too slow to download).

Thanks anyway.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now