1

I use CardLayout with MVC and try to understand, when i should create the Panels used by the CardLayout.

For Example:

A DetailPanel to view and edit the Details of a DataItem is shown, when i select the DataItem on a ListPanel. Should i create and show DetailPanel when i select the DataItem, or should i create the DetailPanel at the start of my Application and just call a load method, when i select the DataItem, and then show the DetailPanel?

Currently i'm using CardLayout like a Stack. I add a Panel when i need it and remove it when i'm done editing.

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
Martin Weber
  • 3,752
  • 4
  • 19
  • 22

1 Answers1

2

Try to avoid replacing view components. Initially, create as much of a DetailPanel as possible and update the component models in your ListSelectionListener. Use CardLayout for the variable portion of each DetailPanel. It's unlikely that creating the view will have a perceptible performance impact; profile to see. If you find that constructing the model introduces significant latency, consider SwingWorker, illustrated here and here.

Community
  • 1
  • 1
trashgod
  • 200,320
  • 28
  • 229
  • 974