[英]Adding components to JTabbedPane
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. 当我运行代码时,所有组件,JTable或按钮都不会显示在选项卡中,而是显示在选项卡窗口的侧面。 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 因为您将JTabbedPane
添加到panel
,然后您编写了
JPanel panel = new JPanel();
and added other components, incl. 并添加了其他组件,包括 the JScrollPane
and buttons to it. JScrollPane
及其按钮。 First, the code cannot compile this way. 首先,代码无法以这种方式编译。 Second, please, change the addition order and add scroll pane to tabs 其次,请更改添加顺序并将滚动窗格添加到选项卡
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.