I want to create a JTabbedPane
for separate items, with JPanel
and GridBaglayout
, but every time, the second tab of the JTabbedPane
bug my text field objects...
that is my animal register class, the extended class and the main class the problem is in the text field of the second table.
the Code, only the problem...
Code:
public class Cad_Animals extends Register_Screen{
JTextField number = new JTextField(10);
JTextField name = new JTextField(30);
JTabbedPane pane1 = new JTabbedPane(1);
JTabbedPane pane2 = new JTabbedPane(1);
JTextField race = new JTextField(10);
JTextField proprietario = new JTextField(10);
JPanel jl1 = new JPanel();
JPanel jl2 = new JPanel();
JTextField father = new JTextField(10);
JTextField mother = new JTextField(10);
public Cad_Animals(){
super("Animal Register");
jl1.setLayout(new GridBagLayout());
jl2.setLayout(new GridBagLayout());
addComponent(1, 1, 1, 1, number,jl1);
addComponent(2, 1, 1, 1, name,jl2);
addComponent(3, 1, 1, 1, proprietario,jl1);
addComponent(2, 1, 1, 1, race,jl2);
addComponent(6, 1, 1, 1, father,jl1);
addComponent(7, 1, 1, 1, mother,jl1);
//pane1.addTab("table1", jl2);
//pane2.addTab("table2", jl1);
//addComponent(8, 1, 6, 6, pane1,1);
// addComponent(8, 2, 3, 3, pane2,1);
//painels("new2",jl2);
//painels("new2", jl1);
pack();
}
}
.
public class Register_Screen extends JFrame {
JTabbedPane la = new JTabbedPane();
public Register_Screen(String titulo) {
super(titulo);
getContentPane().setLayout(new BorderLayout());
setVisible(true);
pack();
}
public void addComponent(int line, int column, int height, int width, JComponent component,JComponent compnum) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridy = line;
gbc.gridx = column;
gbc.gridheight = 1; //1
gbc.gridwidth = 1; //1
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(1, 5, 3, 5);
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridx++;
gbc.gridheight = height;
gbc.gridwidth = width;
//jpCampos.add(component, gbc);
compnum.add(component, gbc);
getContentPane().add(la);
la.addTab("West",compnum);
//jtpTabs.add("asdsa",jpCampos);
}
}
.
public class MainClass {
public static void main(String args[]) throws InterruptedException{
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Não foi possivel Carregar NimbusLookandFeel");
}
Cad_Animals cad = new Cad_Animals();