Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom label+text field component  RSS feed

 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been having a problem with easily getting multiple pairs of labels and text fields on a JFrame. Not actually a problem, but a hassle. If I want this -
My Label ----Text Field----
Anthr Lbl ----Text Field----
Third Lbl ----Text Field----
(Thats really rough ASCII'ish art!)
I find myself having to do one of 2 things -
- Create a panel and set its layout manager to gridbag or grid, then add each pair of components
- Create a panel and set the manager to box layout, then create a sub-panel for each label/text field pair using a flow layout
My solution is to create a custom JComponet, which has a label and a text field combined. It has to at least act this way, internally it can be whatever works best.
Does anyone have any suggestions for how to implement this?
Can I do it by actually using a label and text field internally?
All help appreciated!
Regards,
Aaron R>
[ December 29, 2003: Message edited by: Aaron Roberts ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would just make a new "component" of a JPanel with a JLabel and a JTextfield inside it, and add some methods to the class to set and get the text from the label and textfield. It would be just like the sub-panel in the box layout example you gave, only the subpanel will be a separate class.
[ December 30, 2003: Message edited by: Nathan Pruett ]
 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a plan.
I have a layout I did, not related to this one, where I couldn't figure out a solution, except to layer 3 or 4 panels inside each other. I'm worried about performance, due to all the nested panels. Is that really an issue? Should I even be concerned with that here with my 'component'?
Regards,
Aaron R>
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The impact to performance would be negligible... if any. If it was thousands of panels, maybe, but if you are using thousands of panels, you don't have a good GUI design in the first place.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!