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.
When to create a Panel for CardLayout?
-
02-04-2022 - |
Question
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.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow