I have this panel:
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);
}
}
Then when I enter some characters into the JTextPane it is automatically resized. With 200 characters on the same line (on the text pane), the 2 JTables are not visible anymore.
How can I do to fix the width of my JTextPane?
Thanks.
Finally I used a FormLayout from JGoodies.
For all the situations I tested (resizing, empty/filled components, etc.) it was more predictable.
Note that you have to call
getTableHeader()explicitly because the JTables are not directly in a JScrollPane.Thanks.