When I run the code , none of the components, neither the JTable or the buttons will show up inside the tab, they appear on the side of the tab window instead. any reason why that is ?
public void GUIcode() {
setLayout(new GridBagLayout());
setBounds(100, 100, 450, 300);
panel = new JPanel();
panel.setBorder(new EmptyBorder(10, 10, 10, 10));
setContentPane(panel);
panel.setLayout(null);
JTabbedPane tabb = new JTabbedPane(JTabbedPane.TOP);
tabb.setBounds(0, 0, 400, 300);
panel.add(tabb);
JPanel panel = new JPanel();
tabb.addTab("vis vare", null, panel, null);
panel.setLayout(null);
tabellinnhold = new DefaultTableModel(defaulttabell,kolonnenavn);
bytabell = new JTable(tabellinnhold);
rullefelt = new JScrollPane(bytabell);
panel.add(rullefelt);
add(panel);
koble = new JButton("koble til");
lukke = new JButton("lukke");
hente = new JButton("Hente data");
avslutt = new JButton("Avslutt");
// legger til knappepanel
panel.setLayout(new GridLayout(1,4));
panel.add(koble);
panel.add(lukke);
panel.add(hente);
panel.add(avslutt);
//action drit
koble.addActionListener(this);
lukke.addActionListener(this);
hente.addActionListener(this);
avslutt.addActionListener(this);
}
Because you added the JTabbedPane
to panel
and then you wrote
JPanel panel = new JPanel();
and added other components, incl. the JScrollPane
and buttons to it. First, the code cannot compile this way. Second, please, change the addition order and add scroll pane to tabs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.