JComboBox

Discussion in 'Java' started by Ouabaine, Dec 15, 2007.

  1. Ouabaine

    Ouabaine Guest

    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
    Ouabaine, Dec 15, 2007
    #1
    1. Advertising

  2. Ouabaine

    Roedy Green Guest

    On Sat, 15 Dec 2007 16:41:30 +0100, "Ouabaine" <>
    wrote, quoted or indirectly quoted someone who said :

    > 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.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Dec 15, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manoj Nair
    Replies:
    0
    Views:
    1,483
    Manoj Nair
    Sep 12, 2003
  2. Ike

    Objects in a JComboBox

    Ike, Sep 13, 2003, in forum: Java
    Replies:
    3
    Views:
    10,215
  3. Sudarshan Raghavan

    JComboBox limit

    Sudarshan Raghavan, Sep 29, 2003, in forum: Java
    Replies:
    2
    Views:
    559
    nielinjie
    Sep 29, 2003
  4. f
    Replies:
    1
    Views:
    4,883
    Steve Claflin
    Oct 8, 2003
  5. nuria
    Replies:
    0
    Views:
    632
    nuria
    Nov 25, 2003
Loading...

Share This Page