-1
我想隐藏在秋千显示FXPanel控制在JavaFX应用程序隐藏和Swing的JFrame中显示JFXPanel
我想在点击一个按钮FXPanel控制应该被隐藏,并在点击其他控制应该再次显示它是被隐藏不再可见。
使用以下代码。
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.setVisible(true);
}
if(ae.getActionCommand().equals("hide"))
{
fxpanel.hide();
}
Platform.runLater(new Runnable())
{
public void run()
{
init Fx(fxpanel);
}}
);
}
private static void initFX(final JFXPanel fxpanel)
{
Group group = ne Group();
Scene scene= new Scene(group);
fxpanel.setScene(scene);
WebView webview= new WebView();
group.getChildren().add(webview);
webview.setMinSize(500,500);
webview.setMaxSize(500,500);
eng=webview.getEngine();
File file= new File("d:/new folder/abc.html");
try
{
eng.load(file.toURI().toURL().toString());
}
catch(Exception ex)
{
}
}
public static void main(String args[])
{
abc f1= new abc();
f1.show();
}
}
@ sarcan统筹不是问题,问题是,如果我做调用setVisible(假)的JFXPanel则不能再次调用setVisible(真)还怎么可能。 –
我看到你更新了上面的代码,但是你仍然缺少setActionCommand调用。添加'b1.setActionCommand(“OK”); b2.setActionCommand(“隐藏”);'到你的构造函数,否则你的动作侦听器的代码不会做任何事情。 – sarcan
告诉你是否可以如何让它再次可见 –