• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Q.Combine Swing components to simplify

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I have common patterns of fields in a Swing application GUI (JFrame),
what's the best approach for combining them into classes? (Links to articles or tutorials re welcome.) The goal is to reduce component count.


e.g. "Full Name " // JLabel
["John Doe" ] // JTextField


[ August 04, 2008: Message edited by: Mike Rainville ]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put them in a JPanel, or extend JPanel, and add the components to it.

Typically:

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you will still have the same number of components on the component tree. Are you looking for a simpler layout of components?
 
Mike Rainville
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gil,

The same patterns, as above, a label over a text field, or in other cases, two related text fields and a button, repeat frequently. It's mainly about reducing the number of individual components, by dealing with them at higher levels of abstraction,and encapsulating the interactions that repeat throughout the application.

It's also possible that I could use Tables (JTable, JXTable) to deal with entire database tables, or filtered results, as a single component.

As the first response shows, Swing deals with each item separately, which tends to multiply the number of components rapidly.

Is there a "best" approach for combining standard components so they act as one for most purposes?
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic