• Post Reply Bookmark Topic Watch Topic
  • New Topic

Q.Combine Swing components to simplify

 
Mike Rainville
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ted Smyth
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put them in a JPanel, or extend JPanel, and add the components to it.

Typically:

 
G Estes
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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: 36
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!