T
tomzhi
I am new to Java, learning GUI. I am trying to create a TabbedPane
with 10 tabs, by using array of JPanel. However, JPanel arrays are
always null. I do not understand why they are null when they are
arrays but not otherwise. I would appreciate explanation and help on
this code. Thanks
public static void main(String[] args) {
JTabbedPane tab = new JTabbedPane();
int i;
JTextField[] text = new JTextField[10]; //
textfield to add to each panel
JPanel [] panel = new JPanel[10]; //array
of panel
//name of each tab
String [] name = {"One",
"Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"};
for (i=1;i<10;i++) {
panel.add(text); //
NullPointerException here
tab.addTab(name,panel);
}
System.out.println(tab);
JFrame frame = new JFrame("Testing");
frame.add(tab);
frame.setSize(500,500);
frame.setVisible(true);
}
with 10 tabs, by using array of JPanel. However, JPanel arrays are
always null. I do not understand why they are null when they are
arrays but not otherwise. I would appreciate explanation and help on
this code. Thanks
public static void main(String[] args) {
JTabbedPane tab = new JTabbedPane();
int i;
JTextField[] text = new JTextField[10]; //
textfield to add to each panel
JPanel [] panel = new JPanel[10]; //array
of panel
//name of each tab
String [] name = {"One",
"Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten"};
for (i=1;i<10;i++) {
panel.add(text); //
NullPointerException here
tab.addTab(name,panel);
}
System.out.println(tab);
JFrame frame = new JFrame("Testing");
frame.add(tab);
frame.setSize(500,500);
frame.setVisible(true);
}