I am trying to create a form in MigLayout. I want for any text fields to be labeled with a small JLabel preceding it, with the text field growing as space is available. I am successfully able to do this in the following code:
JFrame frame = new JFrame("Test");
JPanel panel = new JPanel(new MigLayout("", "fill", ""));
panel.add(new JLabel("Testing"));
panel.add(new JTextField(), "growx, pushx, wrap");
frame.setContentPane(panel);
frame.pack();
frame.setMinimumSize(new Dimension(400, 100));
frame.setPreferredSize(new Dimension(400, 100));
frame.setVisible(true);
The result looks like this, which is as expected (the JLabel is the minimum necessary size, the JTextField takes up the rest of the area):
However, if I put a JEditorPane below this and have it span the length of the whole window, the JLabel becomes larger and grows if I enlarge the window. The code change looks like this:
...
panel.add(new JTextField(), "growx, pushx, wrap");
//New line of code here:
panel.add(new JEditorPane(), "growx, pushx, span");
frame.setContentPane(panel);
...
Which causes a result that I do not expect (the JLabel has grown):
I've tried to fix this by adding MigLayout parameters for the JLabel, like "growx 0"
and "shrink"
, but this doesn't seem to have any effect on the size of the label.
How can I prevent the JLabels from growing in a situation like this?