在具有绝对布局的框架中添加带有按钮、标签的 JTabbedPane
我有一个java代码。
package interfaces;
import javax.swing.JPanel;
public class TabbedPaneDemo extends JPanel {
public TabbedPaneDemo() {
JTabbedPane pane = new JTabbedPane();
JPanel dashboardPanel = new JPanel();
dashboardPanel.add(new JLabel("Dashboard"));
// Add Dashboard Tab
pane.addTab("Dashboard", dashboardPanel);
JPanel transactionPanel = new JPanel();
transactionPanel.add(new JLabel("Transactions"));
// Add Transactions Tab
pane.addTab("Transactions", transactionPanel);
JPanel accountPanel = new JPanel();
accountPanel.add(new JLabel("Account"));
// Add Account Tab
pane.addTab("Account", accountPanel);
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(400, 200));
this.add(pane, BorderLayout.CENTER);
}
public static void main(String[] args) {
JPanel panel = new TabbedPaneDemo();
panel.setOpaque(true);
// panel.setBounds(12, 12, 45, 98);
JFrame frame = new JFrame("JTabbedPane Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}}
和输出它!
我想将此代码更改为这样。
我想使用绝对布局(空)。 我想用这些选项卡添加菜单、按钮和标签...
我该怎么办?
I have a code in java.
package interfaces;
import javax.swing.JPanel;
public class TabbedPaneDemo extends JPanel {
public TabbedPaneDemo() {
JTabbedPane pane = new JTabbedPane();
JPanel dashboardPanel = new JPanel();
dashboardPanel.add(new JLabel("Dashboard"));
// Add Dashboard Tab
pane.addTab("Dashboard", dashboardPanel);
JPanel transactionPanel = new JPanel();
transactionPanel.add(new JLabel("Transactions"));
// Add Transactions Tab
pane.addTab("Transactions", transactionPanel);
JPanel accountPanel = new JPanel();
accountPanel.add(new JLabel("Account"));
// Add Account Tab
pane.addTab("Account", accountPanel);
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(400, 200));
this.add(pane, BorderLayout.CENTER);
}
public static void main(String[] args) {
JPanel panel = new TabbedPaneDemo();
panel.setOpaque(true);
// panel.setBounds(12, 12, 45, 98);
JFrame frame = new JFrame("JTabbedPane Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(panel);
frame.pack();
frame.setVisible(true);
}}
and the output it's !
I want to change in this code to be like this.
I want to use an absolute layout (null).
I want to add menu, buttons and labels with these tabs ...
How can I do??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该使用绝对布局。没有理由使用绝对布局。
相反,您应该使用布局管理器。
也许创建一个面板并向该面板添加按钮。然后将该面板添加到内容窗格的北部。选项卡式窗格将添加到中心。
阅读有关使用布局管理器的 Swing 教程。
You should NOT use absolute layout. There is not reason to use absolute layout.
Instead you should use layout managers.
Maybe create a panel and add buttons to the panel. Then add the panel to the NORTH of the content pane. The tabbed pane would be added to the CENTER.
Read the Swing tutorial on Using Layout Managers.