创建一个JDialog的所有者javafx stage ?

时间:2022-03-01 02:06:22

Display a swings JDialog containing a JRViewer for Jasper Report, from within a javafx application menu item click. BUT the JDialog is not MODAL even after setModal(true) as it is not owned by javafx stage. How to make a javafx stage the owner of a JDialog? Alternatively how to display a Jasper report inside a javafx stage, scene?

在javafx应用程序菜单项中,显示一个包含JRViewer的swing JDialog,用于Jasper报告。但是在setModal(true)之后,JDialog并不是模态的,因为它不是javafx stage所拥有的。如何使javafx stage成为JDialog的所有者?或者如何在javafx stage中显示Jasper报告,场景?

5 个解决方案

#1


2  

Don't use a JDialog. In JavaFX you use Stages. Put your Jasper report inside a Scene, put the Scene in a Stage. I think you can't put Swing components inside JavaFX components, so you must check this link: Integrating JavaFX into Swing Applications

而且不使用。在JavaFX中,使用stage。把你的Jasper报告放在一个场景里,把场景放在一个舞台上。我认为您不能将Swing组件放入JavaFX组件中,因此必须检查这个链接:将JavaFX集成到Swing应用程序中。

Code to make a JavaFX dialog:

创建JavaFX对话框的代码:

            Stage stage = new Stage();
            stage.setTitle("Title");
            stage.setResizable(false);
            stage.initModality(Modality.APPLICATION_MODAL);
            stage.initOwner(primaryStage);
            stage.initStyle(StageStyle.UTILITY);

            (...)

            Scene scene = new Scene(...);
            stage.setScene(scene);

In the code above the Stage will behave exactly like a dialog.

在上面的代码中,Stage将表现得完全像一个对话框。

Also check this:

还要检查:

How to create a JavaFX dialog?

如何创建JavaFX对话框?

Hello World, JavaFX Style

Hello World,JavaFX的风格

#2


2  

Back to the first (base) question: It's not possible to make a Stage the owner of a JDialog. But, after setting the content of the SwingNode

回到第一个(基础)问题:不可能使一个阶段成为一个JDialog的所有者。但是,在设置了SwingNode的内容之后。

swingNode.setContent(xxx);

you can get the parent of xxx (may be the parent of the parent of xxx too...) until you find a (AWT-) Frame or (AWT-) Dialog. In the case of SwingNode it's a JLightweightFrame. This object you can use as the owner to create your JDialog.

在你找到一个(AWT-)框架或(AWT-)对话框之前,你可以得到xxx的父类(也可能是xxx的父类)。对于SwingNode,它是一个JLightweightFrame。您可以使用此对象作为所有者创建您的JDialog。

But, I think there is a bug in the JavaFX SwingNode mechanism. The JDialog appears functionally modal, if you set it modal (setModal(true)), but it may appear behind the main (JavaFX) window. It's still possible to move the main window, to bring it in front and so on, what should not be possible if there is a modal dialog. But this is another topic.

但是,我认为JavaFX SwingNode机制中存在一个bug。如果将其设置为modal (setModal(true)),则JDialog将出现功能模态,但它可能出现在main (JavaFX)窗口的后面。仍然可以移动主窗口,把它放在前面等等,如果有一个模态对话框就不可能。但这是另一个话题。

#3


0  

Alternatively how to display a Jasper report inside a javafx stage, scene?

或者如何在javafx stage中显示Jasper报告,场景?

Output HTML from your Jasper report and load the report in a JavaFX WebView.

从Jasper报告中输出HTML并在JavaFX WebView中加载报表。

Make a javafx stage the owner of a JDialog?

创建一个JDialog的所有者javafx stage ?

I don't think this is possible. What should work instead is to make your application a Swing application and host your JavaFX content inside a JFXPanel inside a Swing JFrame. Then you have no Stage and the owner of the JDialog can be the JFrame hosting the JFXPanel.

我认为这是不可能的。应该做的是让应用程序成为Swing应用程序,并在Swing JFrame中的JFXPanel中托管JavaFX内容。然后,您没有阶段,JDialog的所有者可以是JFXPanel的JFrame。

#4


0  

now it's possible to do that
what you need now is install jdk 8
because swing content in javafx is introduced in jdk8

现在,您需要安装jdk8,因为javafx中的swing内容是在jdk8中引入的。

@FXML
private SwingNode swingNode;
...
JasperPrint jasperPrint = JasperFillManager.fillReport(FileName, hash, connect);
swingNode.setContent(new JRViewer(jasperPrint));

oracle just add tutorial for this too
for the next you can follow this link
oracle tutorial embed swing in javaFX

oracle只是为这个添加了教程,您可以在javaFX中遵循这个链接oracle教程嵌入swing。

#5


0  

I have written a JasperReports print preview stage class in JavaFX 8. It is a pure JavaFX code and there is no need for use of SwingNode class.

我在JavaFX 8中编写了一个JasperReports打印预览级类。它是纯JavaFX代码,不需要使用SwingNode类。

In comparison to the JRViewer it does not support links and parts, but print preview window does not need it anyway. On the other side, code is much, much shorter and therefore it is easy to understand and to adopt further to everyone's needs.

与JRViewer相比,它不支持链接和部件,但是打印预览窗口并不需要它。另一方面,代码要短得多,因此很容易理解,并且可以进一步满足每个人的需求。

Source code for this class is freely available at GitHub repository.

这个类的源代码在GitHub存储库中是免费的。

#1


2  

Don't use a JDialog. In JavaFX you use Stages. Put your Jasper report inside a Scene, put the Scene in a Stage. I think you can't put Swing components inside JavaFX components, so you must check this link: Integrating JavaFX into Swing Applications

而且不使用。在JavaFX中,使用stage。把你的Jasper报告放在一个场景里,把场景放在一个舞台上。我认为您不能将Swing组件放入JavaFX组件中,因此必须检查这个链接:将JavaFX集成到Swing应用程序中。

Code to make a JavaFX dialog:

创建JavaFX对话框的代码:

            Stage stage = new Stage();
            stage.setTitle("Title");
            stage.setResizable(false);
            stage.initModality(Modality.APPLICATION_MODAL);
            stage.initOwner(primaryStage);
            stage.initStyle(StageStyle.UTILITY);

            (...)

            Scene scene = new Scene(...);
            stage.setScene(scene);

In the code above the Stage will behave exactly like a dialog.

在上面的代码中,Stage将表现得完全像一个对话框。

Also check this:

还要检查:

How to create a JavaFX dialog?

如何创建JavaFX对话框?

Hello World, JavaFX Style

Hello World,JavaFX的风格

#2


2  

Back to the first (base) question: It's not possible to make a Stage the owner of a JDialog. But, after setting the content of the SwingNode

回到第一个(基础)问题:不可能使一个阶段成为一个JDialog的所有者。但是,在设置了SwingNode的内容之后。

swingNode.setContent(xxx);

you can get the parent of xxx (may be the parent of the parent of xxx too...) until you find a (AWT-) Frame or (AWT-) Dialog. In the case of SwingNode it's a JLightweightFrame. This object you can use as the owner to create your JDialog.

在你找到一个(AWT-)框架或(AWT-)对话框之前,你可以得到xxx的父类(也可能是xxx的父类)。对于SwingNode,它是一个JLightweightFrame。您可以使用此对象作为所有者创建您的JDialog。

But, I think there is a bug in the JavaFX SwingNode mechanism. The JDialog appears functionally modal, if you set it modal (setModal(true)), but it may appear behind the main (JavaFX) window. It's still possible to move the main window, to bring it in front and so on, what should not be possible if there is a modal dialog. But this is another topic.

但是,我认为JavaFX SwingNode机制中存在一个bug。如果将其设置为modal (setModal(true)),则JDialog将出现功能模态,但它可能出现在main (JavaFX)窗口的后面。仍然可以移动主窗口,把它放在前面等等,如果有一个模态对话框就不可能。但这是另一个话题。

#3


0  

Alternatively how to display a Jasper report inside a javafx stage, scene?

或者如何在javafx stage中显示Jasper报告,场景?

Output HTML from your Jasper report and load the report in a JavaFX WebView.

从Jasper报告中输出HTML并在JavaFX WebView中加载报表。

Make a javafx stage the owner of a JDialog?

创建一个JDialog的所有者javafx stage ?

I don't think this is possible. What should work instead is to make your application a Swing application and host your JavaFX content inside a JFXPanel inside a Swing JFrame. Then you have no Stage and the owner of the JDialog can be the JFrame hosting the JFXPanel.

我认为这是不可能的。应该做的是让应用程序成为Swing应用程序,并在Swing JFrame中的JFXPanel中托管JavaFX内容。然后,您没有阶段,JDialog的所有者可以是JFXPanel的JFrame。

#4


0  

now it's possible to do that
what you need now is install jdk 8
because swing content in javafx is introduced in jdk8

现在,您需要安装jdk8,因为javafx中的swing内容是在jdk8中引入的。

@FXML
private SwingNode swingNode;
...
JasperPrint jasperPrint = JasperFillManager.fillReport(FileName, hash, connect);
swingNode.setContent(new JRViewer(jasperPrint));

oracle just add tutorial for this too
for the next you can follow this link
oracle tutorial embed swing in javaFX

oracle只是为这个添加了教程,您可以在javaFX中遵循这个链接oracle教程嵌入swing。

#5


0  

I have written a JasperReports print preview stage class in JavaFX 8. It is a pure JavaFX code and there is no need for use of SwingNode class.

我在JavaFX 8中编写了一个JasperReports打印预览级类。它是纯JavaFX代码,不需要使用SwingNode类。

In comparison to the JRViewer it does not support links and parts, but print preview window does not need it anyway. On the other side, code is much, much shorter and therefore it is easy to understand and to adopt further to everyone's needs.

与JRViewer相比,它不支持链接和部件,但是打印预览窗口并不需要它。另一方面,代码要短得多,因此很容易理解,并且可以进一步满足每个人的需求。

Source code for this class is freely available at GitHub repository.

这个类的源代码在GitHub存储库中是免费的。