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();
}
}