• 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

Using Flyweight with Panels

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application that uses panels to display data. This can grow into thousands of panels all of the same type. I've been looking into using the flyweight design pattern to lower system resources and make the application faster all around. Can you use the flyweight pattern with JPanels? I've been attempting to do so but haven't had any luck thus far. I've created the factory which works but it only displays the 1 panel which happens to be the last in the list created. Below are some of the requirements I need

1. Each panel has the same appearance
2. Each panel has a different question object attached which holds information about what to display inside the panel
3. Each panel has icons being displayed based on conditions being passed.

What would be my best route for this type of situation? Thanks for the help.
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general a Component object can only be in one Container object. If you add the same Component to a different Container, it will disappear from the first Container. This is what I call the "Houdini Effect".

Kaydell
 
Sloan Bowman
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So basically using the flyweight with Panels or any component that needs to have multiple nested components there is no other way other than creating several instances of that component if you want it inside the same nested component correct?
 
Kaydell Leavitt
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that this is true of AWT/Swing. I don't know about SWT.

Kaydell
 
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
Both JTree and JTable use the concept of "Renderers" and "Editors" to do something similiar to the flyweight pattern you're trying.

It sounds like using JTable might work for the situation you describe. The table's data model would be the backing information - the question object and the "conditions being passed". You would create a class that implements TableCellRenderer to provide a graphical display for this information, and a class that implements TableCellEditor to provide a way for the user to change the information.

Java Tutorial section on Table renderers and editors
 
Kaydell Leavitt
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Components such a text components have a related objects that could be re-used. For example, text components have a related Document object, DocumentFilter, and InputerVerifier that might be re-usable.

Kaydell

Java Search
[ July 11, 2007: Message edited by: Kaydell Leavitt ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic