I'm having problems seting up a new Combo box model. My Box Model...
stateBoxModel = new DefaultComboBoxModel(new String[]{state1,state2});
int size;
size = stateBoxModel.getSize();
System.out.println("Size is " + size);
...
Which prints out 2 and I'm sure the state strings have something in them.
But when I use the model...
stateComboBox.setModel(stateBoxModel);
...
I get:
java.lang.NullPointerException
at javax.swing.JComboBox.setModel(JComboBox.java:289)
at Desktop_9.initComponents(Desktop_9.java:389) //this is the
stateComboBox.setModel(stateBoxModel);
at Desktop_9.<init>(Desktop_9.java:90) // initComponents();
at Desktop_9.main(Desktop_9.java:2596)// new Desktop_9().show();
Exception in thread "main"
So I'm not sure why the model is null
Thanks for your time.
Totaly stupid I was initComponants(); before getting the string values and
making the model.
Thanks for your attention.
"newsguy" <wil...@pdfsystems.com> wrote in message
news:d40o2...@news4.newsguy.com...
"newsguy" <wil...@pdfsystems.com> wrote in message
news:d40o2...@news4.newsguy.com...
>>snip<<
public class Combo extends JFrame{
DefaultComboBoxModel dcm;
String state1=new String("bla");
String state2=new String("blah");
JComboBox jc;
public Combo() {
super("Combo");
dcm=new DefaultComboBoxModel(new String[]{state1,state2});
System.out.println(dcm.getSize());
jc=new JComboBox();
jc.setModel(dcm);
add(jc);
setDefaultCloseOperation(EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] a) {
new Combo();}}
REgards
http://www.DevPlug.com --Connecting Developers
Posted from: http://www.devplug.com/ftopic22997.htm