• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextField.setSize()?

 
henry akoma
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic