Why does the following code, placed alone in the constructor of a JPanel subclass, produce a proportional empty space to the left of the split_pane but above mQueryField?
mMessageArea = new JTextArea ();
JScrollPane message_pane = new JScrollPane (mMessageArea);
mTableView = new JTable ();
mTableView.setFillsViewportHeight (true);
JScrollPane table_pane = new JScrollPane (mTableView);
JSplitPane split_pane = new JSplitPane (JSplitPane.VERTICAL_SPLIT,
message_pane, table_pane);
mQueryField = new JTextField ();
mQueryField.setMaximumSize (new Dimension (Short.MAX_VALUE, 20));
setLayout (new BoxLayout (this, BoxLayout.Y_AXIS));
add (split_pane);
add (mQueryField);
EDIT – SSCCE:
import java.awt.Dimension;
import javax.swing.*;
public class SSCCE extends JPanel
{
private JTextArea mMessageArea;
private JTable mTableView;
private JTextField mQueryField;
public SSCCE ()
{
mMessageArea = new JTextArea ();
JScrollPane message_pane = new JScrollPane (mMessageArea);
mTableView = new JTable ();
mTableView.setFillsViewportHeight (true);
JScrollPane table_pane = new JScrollPane (mTableView);
JSplitPane split_pane = new JSplitPane (JSplitPane.VERTICAL_SPLIT,
message_pane, table_pane);
mQueryField = new JTextField ();
mQueryField.setMaximumSize (new Dimension (Short.MAX_VALUE, 20));
setLayout (new BoxLayout (this, BoxLayout.Y_AXIS));
add (split_pane);
add (mQueryField);
}
public static void main (String[] args)
{
JFrame frame = new JFrame ();
frame.add (new SSCCE ());
frame.setVisible (true);
frame.pack ();
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
}
}
Perhaps it’s due to the JSplitPane’s maximum size not being big enough. You can either set this or nest it in a JPanel that uses BorderLayout:
1+ for the SSCCE by the way. It makes working with your problem much easier.
Edit:
I was wrong, the problem is simply one of alignment as JTextFields default to an x alignment of Component.CENTER_ALIGNMENT. The solution is set set the X alignment to the left: