aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextField.setSize()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField.setSize()?" Watch "JTextField.setSize()?" New topic
Author

JTextField.setSize()?

henry akoma
Greenhorn

Joined: May 17, 2005
Posts: 21
hi,

please can someone help me understand why the method setSize(int w, int h) does not set the size of a JTextField:

JTextField.setSize(int w,int h)

And please, what method can do this.

THANX IN ADVANCE.
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
Is your component inside a panel with a layout manager? A layout manager will reset the size of your component based on various constraints. You can use the setPreferredSize() method instead of setSize() to tell most layout managers what size the field should be.
Tom McC
Greenhorn

Joined: Jul 28, 2005
Posts: 21
If what David said doesn't do what you want it to, check out the setColumns(int) method of JTextField; It should set how many characters you want to be able to fit in the field, which I believe will make it longer.

Tom
Brad Bahls
Greenhorn

Joined: Aug 21, 2009
Posts: 1
this thread is a bit old but here's a good explanation of how gridbag can mess with a JTextField. The link also has many good hints on other gridbag goodies.

http://www.jakemiles.com/gridBag

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40034
    
  28
Brad Bahls wrote:this thread is a bit old . . .
True. There is a good chance the original poster is no longer reading. I liked the link, but the constraints class of Cai Horstmann's seems better.

And welcome to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextField.setSize()?