[英]Adding a Tabbed Pane to a Panel using Layout managers
I am simply trying to add a tabbed pane with 5 tabs onto a panel, although only the final tab ( tab e ) is being shown. 我只是试图在面板上添加具有5个选项卡的选项卡式窗格,尽管仅显示了最后一个选项卡( tab e )。
I am obviously doing something fundamentally wrong here, I have tried changing the layout manager of the Panel the tabbed pane is being added to but I don't think this is the problem. 我显然在这里做了根本上错误的事情,我尝试更改添加了选项卡式窗格的Panel的布局管理器,但是我不认为这是问题所在。 Any adivce would be helpful thanks!
任何地方都会有所帮助,谢谢!
Main Class Code: 主类代码:
public static void main(String[] args) {
JFrame frame = new JFrame("Data Structures Program");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 600);
GraphicPanel G = new GraphicPanel();
frame.add(G.getPanel());
frame.setVisible(true);
}
Graphics Class 图形类
public class GraphicPanel {
public JPanel topPanel;
public GraphicPanel() {
JPanel Panel = new JPanel();
Panel.setLayout(new GridLayout(1, 1));
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("a", Panel);
tabbedPane.addTab("b", Panel);
tabbedPane.addTab("c", Panel);
tabbedPane.addTab("d", Panel );
tabbedPane.addTab("e", Panel );
topPanel = new JPanel();
topPanel.setLayout(new GridLayout(1, 1));
topPanel.add(tabbedPane);
}
public JPanel getPanel(){
return topPanel;
}
}
you must creates new instance of JPanel
if you want to show in JTabbedPane
如果要在
JTabbedPane
显示,则必须创建JPanel
新实例
try this code: 试试这个代码:
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("a", new Panel());
tabbedPane.addTab("b", new Panel());
tabbedPane.addTab("c", new Panel());
tabbedPane.addTab("d", new Panel());
tabbedPane.addTab("e", new Panel());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.