且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用JTabbedPane在一个JPanel中放置多个JPanels(3)?

更新时间:2023-12-05 23:20:40

I am trying to create a gui app using JTabbedPane to create 5 tabs. Each tab contains a panel with 3 panels in it

正如Swing组件的性质一样,除了JFrame之外,您还可以将一个JComponent嵌入另一个内.
因此,您需要做的是创建一个JPanel.确保它具有3个列和1行的GridLayout(或者,如果需要,反之亦然).
然后,将三个JPanels添加到具有网格布局的此基本JPanel中.

As is the nature of Swing components, you can embed one JComponent inside another except for JFrame.
So, what you need to do is to create a JPanel. Make sure it has a GridLayout for 3 cols and 1 row (or the other way around, if that is your need).
Then, add the three JPanels to this base JPanel which has grid layout.

最后,将基本JPanel添加到您的JTabbedPane中.看一下JPanel教程: http://docs.oracle .com/javase/tutorial/uiswing/components/tabbedpane.html

Finally, add the base JPanel to your JTabbedPane. Have a look at the JPanel tutorial: http://docs.oracle.com/javase/tutorial/uiswing/components/tabbedpane.html