1
我有初始化一個JPanel。這裏的一個問題一個Swing的JPanel是我的代碼:`初始化與另一個
JPanel canvas = new JPanel();
JPanel can = canvas;
System.out.println("COMPONENTS 1 :" + canvas.getComponentCount());
System.out.println("COMPONENTS 1 :" + can.getComponentCount());
JTextField txt = new JTextField();
txt.setBounds(100, 100, 200, 30);
can.add(txt);
System.out.println("COMPONENTS 2 :" + canvas.getComponentCount());
System.out.println("COMPONENTS 2 :" + can.getComponentCount());
`
輸出爲:
COMPONENTS 1 :0
COMPONENTS 1 :0
COMPONENTS 2 :1
COMPONENTS 2 :1
我想要什麼:
COMPONENTS 1 :0
COMPONENTS 1 :0
COMPONENTS 2 :0
COMPONENTS 2 :1