This has nothing to do with
JTabbedPane and everything to do with understanding
GridBagLayout. Please if the whole dialog changes to very small, than disappeared the textfield!.
Do
not set bounds. Do
not set preferredSize. Do
not make irrelevant calls to setXAlignment. Read the API for that method. It has nothing to do with how components are laid out within the container on which the method is invoked. Do
not add Box's horizontal
struts in a GridBagLayout.
Use the constructor of JTextField that takes an int columns parameter and pass an appropriate value. Use weightx of
GridBagConstraints to indicate how extra space should be allotted, ipadx/ipady to indicate how you would like a component to be enlarged, and insets to indicate the empty space you would like around the component. Recommended reading:
How to Use GridBagLayout. And don't just read: do the exercises and experiment with changes to the sample code. GridBagLayout can take time to learn, but only because it gives you, the programmer, more power over the niceties of the layout.
if the whole dialog changes to very small, than disappeared the textfield!
It doesn't disappear. When GridBagLayout is unable to allot the preferredSize it shrinks the component to its minimumSize (horizontal and vertical are handled separately).