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