How to set the size on a JComboBox

Discussion in 'Java' started by Aaron Fude, Dec 17, 2008.

  1. Aaron Fude

    Aaron Fude Guest

    Hi,

    I would like to set the width of a JComboBox to the widest item that
    it contains. How does one do that after all the items have been added
    to the JComboBox?

    Many thanks in advance,

    Aaron
     
    Aaron Fude, Dec 17, 2008
    #1
    1. Advertising

  2. On Dec 17, 3:21 pm, Aaron Fude <> wrote:
    > ...
    > I would like to set the width of a JComboBox to the widest item that
    > it contains.


    <sscce>
    import javax.swing.*;

    class ComboWidthTest {

    public static void main(String[] args) {
    String[] items = {
    "a",
    "b",
    "c",
    "dddddddddddddddddddddddddddddddddddddd",
    "e"
    };
    JComboBox combo = new JComboBox(items);
    JOptionPane.showMessageDialog(null, combo);
    }
    }
    </sscce>

    >..How does one do that after all the items have been added
    > to the JComboBox?


    It is usually automatic, unless any of
    a number of silly things have been done
    by one in the code that one is asking us
    to guess about.

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Dec 17, 2008
    #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. =?Utf-8?B?QmlkYXJrb3Rh?=

    How to set the DataGrid Row Size to a fixed size.

    =?Utf-8?B?QmlkYXJrb3Rh?=, May 19, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    856
    =?Utf-8?B?QmlkYXJrb3Rh?=
    May 19, 2005
  2. Bobby
    Replies:
    0
    Views:
    521
    Bobby
    Jan 7, 2005
  3. Bobby
    Replies:
    1
    Views:
    8,294
    John St. Ledger
    Jan 7, 2005
  4. Yulia
    Replies:
    1
    Views:
    702
    Andrew Thompson
    Jul 4, 2005
  5. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,734
    Michael Jung
    May 25, 2008
Loading...

Share This Page