Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Giving TextFields names  RSS feed

 
Colin Gebler
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi is it possible to give TextFields names with Swing?So in the actual GUI it shall say

a:[Textfield]
b:[Textfield]

I tried doing it with labels but it does not really fit next to the fields.I also searched google but what i find there is about giving them ID`s for debugging.

Mfg
Colin Gebler
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure.
Add the label and the text field to a JPanel (with required layout) and then add the panel to the parent.
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi is it possible to give TextFields names with Swing?So in the actual GUI it shall say

a:[Textfield]
b:[Textfield]


yes it is

- setName("String")

better could be, because you can to multiple this Object, and best of solutions for 2nd part of your question

- get/putClientPoperty


I tried doing it with labels but it does not really fit next to the fields.I also searched google but what i find there is about giving them ID`s for debugging.

- this is job for LayoutManager,

- or otherwise you can to use JLabel.setLabelFor(someJTextField)
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@m Korbel
I think what the OP means is a label/text field pair on the UI.
 
Colin Gebler
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this does not do what i want.I want the name of the label (a , b,and so on) to be left to the textfields.I try with this piece of code:



it compiles and can be executed ,but the labels are displayed under the text fields(First all text fields and then all Labels)
 
Colin Gebler
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it now.It is easiest using GridBagLayout because it allows me to define the position of all objects very precisely ,which allows me to place the labels next to the correspondending TextField.

Thanks for trying to help me
 
Campbell Ritchie
Sheriff
Posts: 55334
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about a JLabelledTextField class? It has two fields, one a label and the other a text field. You can use the class as a wrapper round those two fields.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!