I would like to have in my app text fields that span multiple rows. It seems to be no problem to get the desired result in Eclipse design viewer using GridBagLayout
:
However, when I export it to jar
, I see the window like this:
My code:
import java.awt.Color;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JTextField;
@SuppressWarnings("serial")
public class TestFrame extends JFrame {
GridBagConstraints constraints;
JTextField text0;
public TestFrame() {
super("Test window");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
Container container = getContentPane();
container.setLayout(new GridBagLayout());
container.setBackground(new Color(240,240,240));
JTextField editableTextField;
editableTextField = new JTextField("Enter text here");
constraints = new GridBagConstraints();
constraints.fill=GridBagConstraints.BOTH;
constraints.gridheight=2;
constraints.gridx=0;
constraints.gridy=0;
container.add(editableTextField, constraints);
pack();
}
public static void main(String args[]) {
new TestFrame();
}
}
I am using Eclipse 4.4.1
under MacOS 10.9.3
.
Can anyone explain me, where the difference in view comes from and how can I get the proper text field height in jar
?