Take the 2-minute tour ×

I have a JTextField as well as a JTextArea in a JFrame. When the application runs however, the JTextField gets resized if I minimize the window. It usually doubles or triples in height, but it's not consistent in how it resizes each time. I have no idea why this could be happening. I'm not really asking for a direct solution, just some possible things that could be causing the problem. If you could help me out here that'd be great. Thanks

EDIT: here's the code I'm using to initialize it:

public class Console extends JPanel implements ActionListener, Serializable {
    boolean ready = false;
    protected JTextField textField;
    protected JTextArea textArea;
    private final static String newline = "\n";
    Game m_game;
    Thread t;

public Console(Game game) {
    super(new GridBagLayout());

    m_game = game;
    textField = new JTextField(20);

    textArea = new JTextArea(20, 60);
    Font comic = new Font("Serif", Font.PLAIN, 14);
    JScrollPane scrollPane = new JScrollPane(textArea);

    //Add Components to this panel.
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = GridBagConstraints.REMAINDER;

    c.fill = GridBagConstraints.HORIZONTAL;
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    add(scrollPane, c);
    add(textField, c);

public void actionPerformed(ActionEvent evt) {
    String text = textField.getText();
    m_game.input = text;
    m_game.wait = false;
    synchronized (m_game){
        ready = true;

public void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("Game");

    //Add contents to the window.
    frame.add(new Console(m_game));

    //Display the window.
share|improve this question
What are you doing code-wise? –  Bhesh Gurung Jan 18 '12 at 18:16
It may be something you're doing with the layout. –  fireshadow52 Jan 18 '12 at 18:22
For better help sooner, post an SSCCE. –  Andrew Thompson Jan 18 '12 at 18:24
Just in case there is any confusion.. "the code I'm using to initialize it:" ..is not an SSCCE. –  Andrew Thompson Jan 18 '12 at 19:14
You might want to remove.. textField.setPreferredSize(null);. –  Andrew Thompson Jan 18 '12 at 19:15
show 1 more comment

1 Answer

up vote 9 down vote accepted

I think it's connected with Layout Manager. http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html

share|improve this answer
add comment

Your Answer


