Solved

JComboBox disappearing drop down button

Posted on 1998-05-25
5
560 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I remove an object from a 3 60
eclipse console opening separately 2 46
ejb mdb examples 1 36
Html split(text) 2 45
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…
Suggested Courses

739 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