For the purpose of discussion and learning for a newbi like me :D
I have a JComboBox in my window , and will fill it after retrieving some values from the Database. I use "addItem" to insert each data (String ) to my ComboBox and it works fine.
The problem was when there is no data retrieved. In this case I just use the same "addItem" function to insert an item to the combobox.
The code above, will return an Null Exception;Code:String noStr = new String("DB Empty");
this.comboDataList.addItem(noStr);
I tried using "insertItemAt()", and it will insert the item to the comboBox but when I tried to select the Item, it will give the same NULL exception.
I found this solution using the "setModel"
This was the solution that works among all the tutorials I found. I probably don't need to loop it since I only have one data to add anyway.Code:
String [] testStr = new String[1];
for(int i=0; i < 1; i++ )
{
testStr[i] = new String("DB Empty");
}
this.comboDataList.setModel(new DefaultComboBoxModel(testStr));
Is there some kind of problem with addItem? Any Idea.
Im using NetBeans IDE 5.5.1 and JDK 1.6
