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.
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.