?
Solved

JComboBox disappearing drop down button

Posted on 1998-05-25
5
Medium Priority
?
571 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
ID: 1221413
Could you post a piece of code showing the unexpected behaviour?
0
 

Author Comment

by:optimal
ID: 1221414
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
ID: 1221415
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
ID: 1221416
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
ID: 1221417
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month16 days, 8 hours left to enroll

862 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