我想在JFrame容器上添加和删除JFXPanel,但无法这样做。我被困在这里,没有得到适当的解决方案的按钮点击,我想添加和删除的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();
}
}发布于 2012-12-06 15:53:56
LayoutManagernull/Absolute show()将JFrame设置为可见?您应该使用setVisible(true)Platform.runLater()在Event Dispatch Thread上通过SwingUtilities.invokeXXX创建和操作Swing组件和JavaFX组件
除了上面的问题之外,你最大的问题是在添加/删除组件后没有刷新GUI/容器,因此没有显示任何更改:
在JFrame实例上调用revalidate()和repaint(),以反映在可见容器中添加/移除组件后的更改。
https://stackoverflow.com/questions/13738294
复制相似问题