Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Textfield size in an Array

 
Dave Morley
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Day

I am currently coding a project for a course, in the project there are an Array of textfields. The only thng is the textfields must be square.

When you declare the textfield you can declare the length but can you also declare the vertical height:

This is how I think it should be coded:

public class Checkerboard extends frame implements ActionListener
{

public TextField checkArray[16] // decalres 16 elements in the array.

and down to the following


public checkerboard()
{
checkArray = new TextField(20,20);// declares the height as 20 and the length as 20???

is this correct???


Any help is greatly appreciated.

Regards
Dave Morley

 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually you do not declare the length of the textfield by passing an int to the constructor. You define the number of characters it can contain (by default). The number of columns will set the preferred size of the component accordingly.

If you want the textfields to be square you will have to set the bounds of those textfield.

If you set the PrefferedSize of a component the layout manager will use this if enough space is available on the parent component. There is also something called minimumSize. If the layout manager notices that the parent component is to small for the child to fit. It will shrink the component taking in account the minimumsize.

You actually have to call the setPreferredSize(int width,int height) method for every component (textfield) that you wish to add. Be aware that the layout manager will also play with the sizes however. If you just want to add a number of textfields on a panel you can use the FlowLayout for instance.
 
Dave Morley
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Manuel

I get it!!!

Regards
Dave Morley
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic