界面布局有点问题,下面的这个东西好像不能按照我设定的大小进行调整的,每次弹出来的东西,很小的,中间有一个JTabbedPane 为什么不能外面的 JFrame 把它紧紧地包住呢?JTabbedPane 的尺寸是 tabbedPane.setSize(450, 700);感觉外面的 JFrame 的尺寸是小于450*700的
public class testfunction { public static void main(String[] args) throws IOException {
JTabbedPane tabbedPane = new JTabbedPane();
JComponent panel1 = new JPanel();
JComponent panel2 = new JPanel(); tabbedPane.addTab("Tab 1", null, panel1, "tip");
tabbedPane.addTab("Tab 2", null, panel2, "tip2");
panel1.setSize(400, 600);
panel2.setSize(400, 600);
tabbedPane.setSize(450, 700);
JFrame frame = new JFrame("TabbedPaneDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
JLabel filler = new JLabel("Simulation Setting");
filler.setHorizontalAlignment(JLabel.CENTER);
filler.setFont(new Font("SansSerif", Font.BOLD, 20));
frame.add( filler, BorderLayout.PAGE_START);
frame.add( new JLabel("Simulation Setting"), BorderLayout.PAGE_END);
frame.add( new JPanel(), BorderLayout.EAST);
frame.add( new JPanel(), BorderLayout.WEST);
frame.add( tabbedPane, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}}
public class testfunction { public static void main(String[] args) throws IOException {
JTabbedPane tabbedPane = new JTabbedPane();
JComponent panel1 = new JPanel();
JComponent panel2 = new JPanel(); tabbedPane.addTab("Tab 1", null, panel1, "tip");
tabbedPane.addTab("Tab 2", null, panel2, "tip2");
panel1.setSize(400, 600);
panel2.setSize(400, 600);
tabbedPane.setSize(450, 700);
JFrame frame = new JFrame("TabbedPaneDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
JLabel filler = new JLabel("Simulation Setting");
filler.setHorizontalAlignment(JLabel.CENTER);
filler.setFont(new Font("SansSerif", Font.BOLD, 20));
frame.add( filler, BorderLayout.PAGE_START);
frame.add( new JLabel("Simulation Setting"), BorderLayout.PAGE_END);
frame.add( new JPanel(), BorderLayout.EAST);
frame.add( new JPanel(), BorderLayout.WEST);
frame.add( tabbedPane, BorderLayout.CENTER);
//Display the window.
frame.pack();
frame.setVisible(true);
}}
frame.pack()也会自动改变大小的,去掉试试