Solved

JComboBox disappearing drop down button

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

690 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