Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField(int col)  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What the heck does the colunm value in a JTextField constructor do? It doesn't seem to make a difference whether I use it or not.
 
basha khan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does make the difference
JTextField()->empty textfield
JTextField(10)->textfiels with 10 columns(the column width 'll change slightly according to size of font)
JTextField(100)->textfield with 100 columns(mean can hold 100 chars not 100 pixels)
basha
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why. It doesn't actually place any constraints on the TextField as far as user input. Why doesn it matter if I tell it to hold 100 characters when my textfield is wider than that anyway, or why tell it to hold 10 characters when my textfield is shorter than that.
I don't know if I am explaining myself correctly, but in my code,

It doesn't matter if I have the 10 in the constructor or not.
 
raj madhuram
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
From the API docs,
columns - the number of columns to use to calculate the preferred width; if columns is set to zero, the preferred width will be whatever naturally results from the component implementation
It just alters the preferred size. If the layout manager honors preferred size, it will use it. By doing setBounds(), you are overriding the layout mechanism also and hence you will not see any effect.
Some more info here:
http://www.developer.com/java/ent/article.php/610011
- Raj
 
basha khan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi greg,
It's for presentation purpose(View in MVC).size does matter,is'nt it?
basha
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!