Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

JFormattedTextField resizing itself

Thread view: 
Steve Jones - 02 Mar 2004 15:22 GMT
Hi,

I have a JFormattedTextField that is embedded in a JPanel using Gridbag
layout.

If update the field programmatically, changing the number of digits on
display, the text field and it's enclosing panel are resized by a small
amount.

Any ideas on how I can stop this.

Cheers,
Karsten Lentzsch - 02 Mar 2004 15:49 GMT
> If update the field programmatically, changing the number of digits on
> display, the text field and it's enclosing panel are resized by a small
> amount.
>
> Any ideas on how I can stop this.

Specify the field's width by setting the number of columns,
or use a layout that doesn't measure the preferred size.

See JTextField#setColumns(int)

Hope this helps,
Karsten
Steve Jones - 02 Mar 2004 17:02 GMT
>> If update the field programmatically, changing the number of digits on
>> display, the text field and it's enclosing panel are resized by a small
[quoted text clipped - 6 lines]
>
> See JTextField#setColumns(int)

Thanks Karsten, your suggestion works fine.

I have just sub classed JFormattedTextField to see what getPreferredSize()
is returning. The width returned changes with the number of characters in
the field, even though the field's size, as set initially by the gridbag
manager, is far larger than the number of digits on display.

When I use setColumns() as you suggest, the width returned by
getPreferredSize() stays the same.

Cheers, Steve.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.