JFXPanel
을 JFrame
컨테이너에 추가하고 제거하고 싶지만 그렇게 할 수 없습니다. 여기에 붙어있어 버튼 클릭에 대한 적절한 해결책을 얻지 못했습니다. JFXPanel
컨트롤을 추가하고 제거하고 싶습니다.스윙 JFrame에서 JFXPanel 추가/제거
이 코드의 잘못된 점은 무엇입니까?
public class abc extends JFrame
{
JFXPanel fxpanel;
Container cp;
public abc()
{
cp=this.getContentPane();
cp.setLayout(null);
JButton b1= new JButton("Ok");
JButton b2= new JButton("hide");
cp.add(b1);
cp.add(b2);
b1.setBounds(20,50,50,50);
b2.setBounds(70,50,50,50);
b1.addActionListener(this);
b2.addActionListener(this);
fxpanel= new JFXPanel();
cp.add(fxpanel);
fxpanel.setBounds(600,200,400,500);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getActionCommand().equals("OK"))
{
fxpanel= new JFXPanel();
cp.add(fxpanel);
fxpanel.setBounds(600,200,400,500);
}
if(ae.getActionCommand().equals("hide"))
{
cp.remove(fxpanel);
}
}
public static void main(String args[])
{
abc f1= new abc();
f1.show();
}
}
이 코드의 내용은 무엇입니까? –
'cp.setLayout (null);'레이아웃을 사용하십시오. '추가 및 제거'는 ['CardLayout'] (http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html)을 참조하십시오. –