This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 88333 - JComboBox has items, but drop down list blank ?
Summary: JComboBox has items, but drop down list blank ?
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: PC Windows XP
: P1 blocker (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-31 15:08 UTC by fni
Modified: 2007-09-26 09:14 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description fni 2006-10-31 15:08:28 UTC
I have a class called : Customer_Contact_Info_Panel which is a Swing JPanel,
inside this class it has a Vector called : Contacts_Id_Vector which holds
Customer Ids. Customer_Contact_Info_Panel has several JTextFields and an
editable JComboBox where user can enter text info, once the text is entered, the
Contacts_Id_Vector is updated with the latest user input.

Customer_Contact_Info_Panel is used inside a first tab of a Jtabbedpane. In a
second tab I have this line :
JComboBox Order_Customer_Id_ComboBox=new
JComboBox(Customer_Contact_Info_Panel.Contacts_Id_Vector);

Order_Customer_Id_ComboBox is where user can select from a drop down list of the
latest Customer Ids.

The problem I have now is : after user entered a new user Id in the first tab
and the Customer_Contact_Info_Panel.Contacts_Id_Vector is updated, when he goes
to the second tab and click on Order_Customer_Id_ComboBox, it drops down an
empty list, I can see it probably has all the list items in it judging from the
height of the list, but the text is not showing, the strange thing is that if I
just click on the blank drop down list, an item will show up in the
Order_Customer_Id_ComboBox, and if I click on it to drop down it again, all the
list items will show up, including the latest item entered from the first tab !
I wonder if there is a way to repaint or refresh the Order_Customer_Id_ComboBox
so that it can show the items when user first click on it ? Is this a bug in
Swing, or is it my fault ?

Using jdk1.6.0

Simplified source code below :

===========================================================

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
 
public class Java_Test extends JPanel
{
  static JTabbedPane Tabbed_Pane=new JTabbedPane();
  JComboBox Contacts_ComboBox;
  Customer_Info_Panel Customer_Info_Panel=new Customer_Info_Panel();
  
  Java_Test()
  {
    JPanel A_Tab_Panel=new JPanel();
    A_Tab_Panel.setPreferredSize(new Dimension(300,200));
    A_Tab_Panel.add(Customer_Info_Panel);
    
    JPanel B_Tab_Panel=new JPanel();
    B_Tab_Panel.setPreferredSize(new Dimension(300,200));
    Contacts_ComboBox=new JComboBox(Customer_Info_Panel.Contacts_Id_Vector);
    Contacts_ComboBox.setMaximumRowCount(30);
    Contacts_ComboBox.setSelectedIndex(-1);
    Contacts_ComboBox.setPreferredSize(new Dimension(129,22));
    B_Tab_Panel.add(new JLabel("Select Customer Info From List :"));
    B_Tab_Panel.add(Contacts_ComboBox);
    
    Tabbed_Pane.addTab("A : Enter Customer Info",null,A_Tab_Panel,null);
    Tabbed_Pane.addTab("B : Use entered info",null,B_Tab_Panel,null);
    
    add(Tabbed_Pane);
    setPreferredSize(new Dimension(500,300));
  }
  
  public static void main(String[] args)
  {
    final Java_Test demo=new Java_Test();
    
    Dimension Screen_Size=Toolkit.getDefaultToolkit().getScreenSize();
    final JFrame frame=new JFrame("JUninstaller");
    frame.add(demo);
    frame.addWindowListener(new WindowAdapter()
    {
      public void windowActivated(WindowEvent e) { }
      public void windowClosed(WindowEvent e) { }
      public void windowClosing(WindowEvent e)  { System.exit(0); }
      public void windowDeactivated(WindowEvent e)  { }
      public void windowDeiconified(WindowEvent e)  { demo.repaint(); }
      public void windowGainedFocus(WindowEvent e)  { demo.repaint(); }
      public void windowIconified(WindowEvent e)  { }
      public void windowLostFocus(WindowEvent e)  { }
      public void windowOpening(WindowEvent e) { demo.repaint(); }
      public void windowOpened(WindowEvent e)  { }
      public void windowResized(WindowEvent e) { demo.repaint(); }  
      public void windowStateChanged(WindowEvent e) { demo.repaint(); }
    });
    frame.pack();
   
frame.setBounds((Screen_Size.width-demo.getWidth())/2,(Screen_Size.height-demo.getHeight())/2-10,demo.getWidth(),demo.getHeight()+38);
    frame.setVisible(true);
  }  
}
 
class Customer_Info_Panel extends JPanel
{
  Vector<String> Contacts_Id_Vector=new Vector<String>();
  JComboBox Contacts_Id_ComboBox=new JComboBox(Contacts_Id_Vector);
  Customer_Info_Panel()
  {
    Contacts_Id_ComboBox=new JComboBox(Contacts_Id_Vector);
    Contacts_Id_ComboBox.setMaximumRowCount(30);
    Contacts_Id_ComboBox.setSelectedIndex(-1);
    Contacts_Id_ComboBox.setEditable(true);
    Contacts_Id_ComboBox.setPreferredSize(new Dimension(129,22));
    Contacts_Id_ComboBox.addActionListener(new ActionListener() 
    {
      public void actionPerformed(ActionEvent evt)
      {
        String
New_Item=Contacts_Id_ComboBox.getSelectedItem()==null?"":Contacts_Id_ComboBox.getSelectedItem().toString().trim();
        if (!Contacts_Id_Vector.contains(New_Item))
Contacts_Id_Vector.add(New_Item);
      }
    });
    add(new JLabel("Please Enter Customer Info Below :"));
    add(Contacts_Id_ComboBox);
    setPreferredSize(new Dimension(270,170));
  }
}


===========================================================

Run the program, do the following :

1. In Tab A, enter "abc", hit Enter key, then goto Tab B and see it ? It's there.

2. In Tab A again, enter "xyz", hit enter key, goto Tab B, now drop down the
list, nothing is there, but you know there are two items in the list. Just click
on the blank list, an item will show up, if you look at the drop down list now,
you can see both "abc" and "xyz".

3. In Tab A again, enter "123", hit enter, and goto Tab B, drop down the list,
what you see ? Nothing ! Click on the last position on the blank list, you will
get "123", and now if you drop down the list again, you will see all 3 items !

Am I doing something wrong ?

Frank
Comment 1 Jiri Prox 2006-10-31 17:31:03 UTC
It is not problem of NetBeans.
It looks like the model of combobox wasn't updated correctly. I'll have to
implement your own combobox model firing all necessary events. For inspiration
see class javax.swing.DefaultComboBoxModel 
Comment 2 Quality Engineering 2007-09-20 09:50:10 UTC
Reorganization of java component