Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a sample code:
 
Sheriff
Posts: 21464
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what the GridBagLayout should take care of. You just need to use the right constraints when adding the component.
 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

 
sindy lee
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!