What's so special about CardLayout vs manual adding/removal of JPanels?

前端 未结 2 368
盖世英雄少女心
盖世英雄少女心 2020-12-09 11:04

There have been many times on StackOverflow where a user asks a question like this...

I have a main JPanel that contains a child JP

2条回答
  •  温柔的废话
    2020-12-09 11:40

    CardLayout has been thoroughly tested and proven to work. It correctly acquires the component-tree lock and performs component validation in order to ensure that nothing can go wrong. Your solution, while it may work most of the time, will fail under certain circumstances.

    This all boils to reinventing the wheel: Why would you want to when such a time-tested class is already available?

提交回复
热议问题