JComboBox

O

Ouabaine

Hello all,

I am programming the ComboBox object of my game creator. So I create a
JComboBox, and adds it to a JPanel which has a layout manager to null. So I
ask for the preferredsize of the combo, and do a setbounds at the wanted
coordinates with the preferred size. The JPanel is set to opaque (as
indicated in Java tutorials).
But I am facing a very strange problem : the top line of the combo box is
not properly drawn. In non-editable mode, the text of the selected element
is drawn, but the arrow (to open the combo) is not drawn. And in editable
mode it is worse, just a gray line is drawn.
But the combo reacts to the mouse, I can click on the gray line to open it,
and the list is displayed.

Have you got any idea about why I get this result? I've been scratching my
head and trying various things with no success. Would it be related to the
fact that my JPanel has a layout manager to null?

If anyone could have an idea...

Francois
 
R

Roedy Green

Would it be related to the
fact that my JPanel has a layout manager to null?

That sort of programming is highly discouraged in Java. The more
Javaesque way it to use a layout or multiple layout managers, writing
a custom layout manager or two if necessary. See
http://mindprod.com/jgloss/layout.html

When you use a null layout manager, you must:

1. manually set the size of every component, width and height.

2. manually set the position of every component, x and y.

3. makes sure the size and position of the container is suitable. You
either set them manually too, or define the min, max, preferred sizes
of the container so the container will be sized and placed in its
layout.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top