Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JComboBox disappearing drop down button

Posted on 1998-05-25
5
Medium Priority
?
570 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

610 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