![](/img/trans.png)
[英]JavaFX ConcurrentModificationException in Alert (dialog)
[英]javafx alert dialog on swing frame
我正在开发一个基于swing和javafx 8的应用程序。在此应用程序中,在swing和jbutton中创建一个框架,并在javafx 8中完成jbutton动作代码,即使用场景。 在这个警报对话框中创建。但是问题是,如果我单击警报对话框以外的任何地方,然后将警报对话框隐藏在秋千框架后面。我希望javafx警报对话框继续创建的秋千框架。秋千架。 请建议......
这是我的代码:
final JFXPanel fxPanel = new JFXPanel();
Platform.runLater(new Runnable() {
public void run() {
initFX(fxPanel);
}
private void initFX(JFXPanel fxPanel) {
// TODO Auto-generated method stub
Scene scene = createScene();
fxPanel.setScene(scene);
}
private Scene createScene() {
Group root = new Group();
Scene scene = new Scene(root);
Alert cn=new Alert(AlertType.CONFIRMATION);
cn.initStyle(StageStyle.UNDECORATED);
cn.setTitle(null);
cn.setHeaderText(null);
cn.setContentText(ProjectProps.rb.getString("msg.play.confirm"));
DialogPane dp=cn.getDialogPane();
dp.getStylesheets().add(getClass().getResource("login.css").toExternalForm());
dp.setStyle("-fx-border-color: black; -fx-border-width: 5px; ");
Optional<ButtonType> result=cn.showAndWait();
if(result.get()==ButtonType.OK){
System.out.println("ok button clicked:"+result.get());
k=0;
} else{
System.out.println("cancel clicked");
k=1;
}
return (scene);
}
});
我不确定您真正想做什么。 在Swing应用程序中,您是否绝对需要JavaFX警报? JDialog在JavaFX上下文中效果很好,而Alert和Dialogs也很好。
您是否尝试使用cn.initModality(Modality.APPLICATION_MODAL)
设置Alert应用程序模式?
也许您可以在这篇文章中找到答案: 如何在Swing Java中制作JFrame模式
这是帖子中建议的代码:
final JDialog frame = new JDialog(parentFrame, frameTitle, true);
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
我将创建一个新的JDialog并将您的主框架(parentFrame)设置为参数,并将您的JFXPanel添加到其内容中。
frame.getContentPane.add(fxPanel)
您可以使用fxPanel.setScene(yourScene)
将FX内容添加到JDialog。
建议示例:
public class Main {
public static void main(String[] args) {
// create parent
JFrame parent = new JFrame("MainFrame");
parent.setSize(500, 500);
// center of screen
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
parent.setLocation(dim.width/2-parent.getSize().width/2, dim.height/2-parent.getSize().height/2);
parent.setVisible(true);
createDialog(parent);
}
private static void createDialog(JFrame parent) {
// create dialogs JFX content
BorderPane layout = new BorderPane();
layout.setTop(new Button("HELLO"));
layout.setBottom(new Button("IT'S ME"));
Scene scene = new Scene(layout);
JFXPanel dlgContent = new JFXPanel();
dlgContent.setScene(scene);
dlgContent.setPreferredSize(new Dimension(200, 200));
dlgContent.setVisible(true);
// create dialog and set content
JDialog dlg = new JDialog(parent, "Dialog", true);
dlg.setLocationRelativeTo(parent);
dlg.getContentPane().add(dlgContent);
dlg.pack();
dlg.setVisible(true);
}
}
希望我能为您服务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.