• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Custom label+text field component

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic