我有这个面板:
public class MyPanel extends JPanel {
public MyPanel() {
super();
this.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
JTable leftTable = new JTable();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.weightx = 0.1;
gbc.weighty = 1.0;
add(leftTable, gbc);
JTextPane textPane = new JTextPane();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 0.4;
gbc.weighty = 1.0;
add(textPane, gbc);
JTable rightTable = new JTable();
gbc.fill = GridBagConstraints.BOTH;
gbc.gridx = 2;
gbc.gridy = 0;
gbc.weightx = 0.5;
gbc.weighty = 1.0;
add(rightTable, gbc);
}
}
然后,当我在 JTextPane 中输入一些字符时,它会自动调整大小。由于同一行上有 200 个字符(在文本窗格上),这 2 个 JTable 不再可见。
如何修复 JTextPane 的宽度?
谢谢。