• Post Reply Bookmark Topic Watch Topic
  • New Topic

trouble setting size of JTextField  RSS feed

 
anitha nair
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi forum,

I am displaying Jtextfields dynamically in a JPanel.My problem is that the textfields are always displayed in a default size(with very less width).The setSize method doesnt seems to work.

Iam doing it in JDEveloper and so tried giving various layout to the panel.Nothing seems to work.

please help me trace my problem.

[code]
tf = new JTextField[parameterCount];

for(int j = 0; j < tf.length; j++)

{

tf[j] =new JTextField();

tf[j].setSize(50,30);

//I TRIED THE FOLLOWING ALSO

//tf[j].setSize(new Dimension(50, 30));

//tf[j].setColumns(10);

parameterPane.add(tf[j],true);

tf[j].setBounds(100,(100+(j*50)),100,10);

} //END OF FOR LOOP
[code]

Thank you
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, we also need to see code relating to "parameterPane"... details about layout of the parent container(s) are much more important to the size of components than attempting to set the size on the component directly.
 
Brian Cole
Author
Ranch Hand
Posts: 936
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by anitha nair:
The setSize method doesnt seems to work.


You probably shouldn't be calling setSize(),
unless your layout manager is null, which I
wouldn't recommend.

Try setPreferredSize() instead. Also take
a look at setColumns() for JTextFields.
 
anitha nair
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My JPanel's layout is flow layout and its preffered size is 500,5000.
seprefferedSize for the textbox doesnt seems to work also the setColum wont work.

What changs will i have to bring about in the JPanel settings in order to get the textfields dimension correct?

Please help.

Regards.
 
Mateus Lucio
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, try to use a GridLayout, just set the GridLayout to how much lines you need and 1 column



i guess this should help
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!