aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to change components(JTextField) size dynamic in  JTabbedPane? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to change components(JTextField) size dynamic in  JTabbedPane?" Watch "How to change components(JTextField) size dynamic in  JTabbedPane?" New topic
Author

How to change components(JTextField) size dynamic in JTabbedPane?

sindy lee
Greenhorn

Joined: Aug 05, 2010
Posts: 14
I have a sample code:
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

That's what the GridBagLayout should take care of. You just need to use the right constraints when adding the component.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

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).


luck, db
There are no new questions, but there may be new answers.
sindy lee
Greenhorn

Joined: Aug 05, 2010
Posts: 14
Thanks for the tip.
But i got no idea, how should i make it. I want it so looks like:
first line: username: field (its size should be changed arbitrarily according to the user "drag" and the text content length)
second line: password: field (its size should be changed arbitrarily according to the user "drag" and the text content length)

I tried it such as:

but the result isn't what i want. Could you please post some sample code?

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to change components(JTextField) size dynamic in JTabbedPane?