This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Textfield size in an Array
 
Similar Threads
component layout not wrapping inside Panel
Checkerboard.java using a component Array and Counter-Controlled Loop
TextField and setEditable
How to (re)paint an AWT applet faster
Dynamic naming for TextField creation! Please Help!