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

    Default Problem with the first value of the JComboBox


    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

    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) {
    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?


  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    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.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on 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