Results 1 to 2 of 2
  1. #1
    nat
    nat is offline Member
    Join Date
    Dec 2013
    Posts
    56
    Rep Power
    0

    Default Problem with the first value of the JComboBox

    Hi,

    I want to add a text as a first value of the combobox.
    I tried with

    cobSections.insertItemAt("Click here to select a link please", 0);
    in the code

    pPaint.setLayout(pPaintLayout);
    {
    cobSections = new JComboBox();
    cobSections.setRenderer(new MapSectionItemRenderer());

    // cobSections.insertItemAt("Click here to select a link please", 0);

    pPaint.add(cobSections, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
    GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
    new Insets(0, 0, 0, 0), 0, 0));

    cobSections.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    cobSectionsActionPerformed(evt);
    }
    });
    }
    but it didn't appear. Still the first entered value appears when the program is run.
    Can anybody tell me please what's wrong with the code, or should I put this line on some other place, or is there any other code, other way to add this text as first value in the combobox?

    Thanks

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,508
    Rep Power
    5

    Default Re: Problem with the first value of the JComboBox

    Check out this ---> How to Use Combo Boxes (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components). That site also contains lots of good info on various aspects of Java including Swing and Collections.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. problem in jComboBox
    By jperson in forum JDBC
    Replies: 1
    Last Post: 05-19-2010, 01:30 PM
  2. ItemListener problem with JComboBox
    By al_Marshy_1981 in forum AWT / Swing
    Replies: 3
    Last Post: 04-16-2010, 10:24 PM
  3. Serious Problem with JComboBox
    By Plissken in forum New To Java
    Replies: 3
    Last Post: 02-02-2010, 10:48 AM
  4. Accessibility of JComboBox problem
    By abedules78 in forum AWT / Swing
    Replies: 0
    Last Post: 12-26-2008, 01:11 PM
  5. Problem with JComboBox and Jlist
    By java_fun2007 in forum New To Java
    Replies: 2
    Last Post: 05-07-2008, 08:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •