Hi I tried to run JTabbedPanel using for loop.. My program is running successfully. But its not creating any Tab file as what i expected. please help me.
public void GenerateGUI() {
jPanel = new JPanel[3];
jSplitPane1 = new JSplitPane();
jTabbedPane1 = new JTabbedPane();
GroupLayout[] jPanelLayout = new GroupLayout[3];
for (int i = 0; i <= noOfTerminals; i++) {
jPanel[i] = new JPanel();
jPanelLayout[i] = new GroupLayout(jPanel[i]);
jPanel[i].setLayout(jPanelLayout[i]);
jPanelLayout[i].setHorizontalGroup(jPanelLayout[i]
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGap(
0, 449, Short.MAX_VALUE));
jPanelLayout[i].setVerticalGroup(jPanelLayout[i]
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGap(
0, 250, Short.MAX_VALUE));
jPanel[i].add(lblOverView);
jTabbedPane1.addTab("OverView", jPanel[i]);
}
setLayout(null);
add(jTabbedPane1);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
pack();
setVisible(true);
setLocationRelativeTo(null);
}
That happens because you use
null
LayoutManager
. So, remove that linesetLayout(null);
and all will work, or change that line to not null value, for example:setLayout(new BorderLayout());
.I recommend you don't use null Layout. Examine
LayoutManager
tutorial. Try for exampleBorderLayout
or other.