• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Flyweight with Panels

 
Sloan Bowman
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • 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.
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that this is true of AWT/Swing. I don't know about SWT.

Kaydell
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic