wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Textfield size in an Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Textfield size in an Array" Watch "Textfield size in an Array" New topic
Author

Textfield size in an Array

Dave Morley
Ranch Hand

Joined: Jul 23, 2004
Posts: 38
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

Joined: Mar 05, 2002
Posts: 229
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

Joined: Jul 23, 2004
Posts: 38
Thank you Manuel

I get it!!!

Regards
Dave Morley
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Textfield size in an Array