textArea = new JTextArea(textString);
JScrollPane text = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
text.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
我将 JScrollPane 文本添加到 JTabbedPane 中,没什么特别的。
但是,当我切换选项卡时,texfield 会扩展并调整整个窗口的大小。
JFrame frame = new JFrame();
frame.setSize(600, 500);
JPanel main = new JPanel();
main.setLayout(new BorderLayout(0,0));
main.setBorder(new EmptyBorder(10, 10, 10, 10) );
textArea = new JTextArea(textString);
JScrollPane text = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
text.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
JTabbedPane tabs = new JTabbedPane();
tabs.add("Text lines", text);
tabs.add("Another", new JPanel());
main.add(new JLabel("test"), BorderLayout.NORTH);
main.add(tabs, BorderLayout.SOUTH);
frame.setContentPane(main);
frame.pack();