I originally posted a question here
I’ve discovered that the JTextField only resizes if the JScrollPane exists. In other words, I can minimize and maximize it all I want until the scrollbar appears (because there is too much text to fit into the window). After that if I minimize the window, the JTextField triples in vertical size. Hopefully this new information will spark a possible solution. Please post if you have any ideas, thank you.
I am not much of a guy who will use GridBagLayout, seems like the whole issue is with your Layout settings in that.
Seems like you missed to read the GridBagLayout Tutorials, it clearly states that ” it is possible to reuse the same GridBagConstraints instance for multiple components, even if the components have different constraints. However, it is recommended that you do not reuse GridBagConstraints, as this can very easily lead to you introducing subtle bugs if you forget to reset the fields for each new instance.”
So after reading that I made a small improvement in your code of my own, hope you wont mind that 🙂
What i did, is that, I made two different objects of GridBagConstraints, one each of your scrollpane and textfield, so that they can have different values. Since you were using the same object for both the components i.e.
Now till scroll bar doesn’t appears all goes well, but once it does and you minimize the window, and then restores the window, then while repainting the window on the screen, since the values for weights is the same for both the components, hence they try to occupy equal area of the window in terms of Y-axis.
So in order to avoid that, I made two objects with different values for weights along Y-Axis, where JTextArea being mighty has been provided with the higher value i.e. weighty = 0.8 and JTextField being not so mighty in terms of its use in the present scenario, hence it’s been given a weight of weighty = 0.2.
I had rebuild the code again for your extra understanding. Using different GridBagConstraint objects for different components is the way out of the mess.
Do have a look at the code now :