JFrame frame = new JFrame("Picture");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
display = new JPanel();
if(event.getSource().equals(birthday)){
background = new JLabel(bday);
display.add(background);
}
else if(event.getSource().equals(cake)){
picture = new JLabel(pastry, SwingConstants.LEFT);
display.add(picture);
}
else if(event.getSource().equals(input)){
word = new JLabel(text);
word.setHorizontalTextPosition(SwingConstants.RIGHT);
word.setVerticalTextPosition(SwingConstants.CENTER);
display.add(word);
}
frame.setPreferredSize (new Dimension(450, 350));
frame.getContentPane().add(display);
frame.pack();
frame.setVisible(true);
これは、スタンドアロン クラス内の ActionListener クラスの一部です。私はコンボボックス/カードレイアウトを持っていました。そのため、あるコンボ ボックス ラベルのボタン (ケーキ) をクリックし、別のコンボ ボックス ラベルの別のボタン (誕生日) をクリックすると、2 つのフレームが表示されました。それらを同じフレームに配置したいのですが、その方法がわかりませんでした。