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
  • 168,117
  • 40
  • 217
  • 433
Martin Weber
  • 3,892
  • 4
  • 20
  • 23

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
  • 203,806
  • 29
  • 246
  • 1,045