This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Here is the question folks: When you create a textfield, Textfield tf = new TextField(30); what is the significane of 30, here. I know that this is not the number of characters that are viewable. Is that the maximum number of characters that can be entered in the field ? I constructed a textfield like the above but was able to add infinite number of characters to it, the user just has to scroll using the arrow keys. thanks
sarim The api doco states that TextField(int) constructs a new empty text field with the specified number of columns. The number of columns is the number of characters that should be viewable, with the proviso that the actual size of the text field you see rendered depends on the font and layout manager. And you can always scroll text fields - the number of columns has nothing to do with a maximum length. The font may be fixed width or proportional, and the number of chars viewable will be affected accordingly. Also, the layout manager may disregard the preferred size of the text field. However, if you use and fixed-width font and a layout manager that repects the preferred size of the text field, then you can see the relationship between number of columns and the actual size. Try this code and you will see that the TextField with 10 columns is twice the length of the one with 20 columns. The fact that you don't fit exactly 10 or 20 chars in may be due to the way the length is calculated from the number of columns.