• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie questions: Finding out TextFieldIT and how to get all the fileds in single row.

 
Chandra S Sekhar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Java pros, I am really a newbie and please bear with my beginner questions:

a) I am trying to validate if a field has validate values in there - but to do that, i need to get the TextFieldID. How can I determine the textfieldID, not that this is a pre-existing screen with many other fields.
b) How can I get the fields to be in one single row. Right now, this new field is getting in the next row. I do have space to place this in the same/existing row.

Please help.

Thanks.
 
Fred Kleinschmidt
Bartender
Posts: 459
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help if you showed us some code. Otherwise we have to guess what your code might look like, and probably give the wrong answers. As for placement of the text fields, what LayoutManager are you using? The default for a JPanel is FlowLayout, which will display items in a horizontal row.
 
Chandra S Sekhar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Fred,

Thanks for the response. Here is how my text/labels are for the first question:

MyViewArea.add(EmpNameLabel);
MyViewArea.add(EmpNameField, "width 90");
MyViewArea.add(EmpNameTitleLabel);
MyViewArea.add(EmpTitleField, "width 50pt");
MyViewArea.add(EmpLocLabel);
MyViewArea.add(EmpLocField,"width 50pt, wrap");

I would like to check to see if EmpNameField has valid values, for that, as I understand it needs the FieldId, how can I determine the FieldID?
Similarly, for the second question, please use the above code, first four labels/text fields are now appearing in first row and the last two in the next row. How to get all of them in the same row?

Thanks for your time and help.

Regards
CS
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don't know about validation but you can probably get everything into a single row quite easily. Go through the Java™ Tutorials and you can find several layouts. You might find Grid (with 1 row) or (better) Box (horizontal) does what you want.
 
Fred Kleinschmidt
Bartender
Posts: 459
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What LayoutManager is MyViewArea using? from the code you show it looks like it is something like MiG. Look at Campbell Ritchie's answer for how to change that.

As for the validation, I don't know what a "FieldID" is - possibly some instance variable of EmpNameField? Even so, I don't see why you would need it - if EmpNameField is a subclass of JTextField, its getText() method will give you the text.
 
Piet Souris
Rancher
Posts: 1638
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Chandra,

if 'EmpNameField' is a JTextField, then you can get the content
simply as follows:

Check s for valid characters.

To get all your components on one row, follow Campbells
advices.
 
Fred Kleinschmidt
Bartender
Posts: 459
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, you should follow the Java conventions - variable names should start with a lower case letter, not a cap.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some people say Mig is a better layout than any of the built‑in layouts.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!