Why I should use a JPanel?

后端 未结 6 1720
你的背包
你的背包 2021-01-13 15:32

What\'s the difference between:

public class Test {

    public static void main(String[] args) {
        JButton button= new JButton(\"1\");
        button.         


        
6条回答
  •  无人共我
    2021-01-13 15:47

    You can use a JPanel to create a reusable building block of your user interface and maintain a single point of maintenance for all instances of it. Let's say you would create a JFrame containing a diff view for two texts. The left and right view are lets say identical twins. It is way easier to create a panel twice and to add these two panels on the frame instead of adding all subsequent components twice into your frame directly.

    Whenever you now have to change the view, let's say you want to add another button, or whatever you can do it at your panel and both - the left and right view will contain the changes immediately.

提交回复
热议问题