为了在JavaFX 11中创建Jasper报告,我使用了动态报告。我正在将报告加载到Swing Node中,但是只有当我单击堆栈窗格区域时,才会显示Jasper报告,并且只有将鼠标悬停在所有这些组件上时,所有其他组件才可见。组件和报告内容不会立即加载,而不是在鼠标悬停时显示,并且在“堆栈窗格”上滚动时显示报告。
因为这是Java 8中的错误,似乎已经解决,但是在Java 11中,我也遇到了同样的问题。
更新资料
由于我没有得到任何回应,并且按照kleopatra的建议,我创建了最少的可复制代码。请调查一下。
JavaFxJasperReportsDemo.java
package demo;
import java.util.ArrayList;
import java.util.List;
import javax.swing.SwingUtilities;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.embed.swing.SwingNode;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.builder.DynamicReports;
import net.sf.dynamicreports.report.builder.column.Columns;
import net.sf.dynamicreports.report.builder.component.Components;
import net.sf.dynamicreports.report.builder.datatype.DataTypes;
import net.sf.dynamicreports.report.constant.HorizontalTextAlignment;
import net.sf.dynamicreports.report.exception.DRException;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.swing.JRViewer;
public class JavaFxJasperReportsDemo extends Application{
@FXML
private StackPane stackPane;
public void start(Stage stage) throws Exception{
try{
System.out.println("Hello");
Parent root = FXMLLoader.load(getClass().getResource("/FXMLJavaFXJasperReportsDemo.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Java FX Demo");
stage.show();
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent arg0) {
Platform.exit();
}
});
}
catch (Exception e){
throw e;
}
}
@FXML
public void loadReport(ActionEvent event) {
JasperReportBuilder report = DynamicReports.report();
List<DemoPOJO> lstDemoPOJOs=new ArrayList<DemoPOJO>();
DemoPOJO demoPOJO=new DemoPOJO();
demoPOJO.setName("ABC");
demoPOJO.setCity("Delhi");
lstDemoPOJOs.add(demoPOJO);
demoPOJO = new DemoPOJO();
demoPOJO.setName("XYZ");
demoPOJO.setCity("Agra");
lstDemoPOJOs.add(demoPOJO);
report
.columns(
Columns.columnRowNumberColumn("S No"),
Columns.column("Name", "name", DataTypes.stringType()),
Columns.column("Address", "city", DataTypes.stringType())
).title(
Components.text("Demo Java Fx Jasper Reports").
setHorizontalTextAlignment(HorizontalTextAlignment.CENTER))
.pageFooter(Components.pageXofY())
.setDataSource(lstDemoPOJOs);
try {
JasperPrint jasperPrintReport=report.toJasperPrint();
SwingNode swingNode = new SwingNode();
AnchorPane.setTopAnchor(swingNode,0.0);
AnchorPane.setBottomAnchor(swingNode,0.0);
AnchorPane.setLeftAnchor(swingNode,0.0);
AnchorPane.setRightAnchor(swingNode,0.0);
JRViewer jrViewer= new JRViewer(jasperPrintReport);
SwingUtilities.invokeLater(() ->swingNode.setContent(jrViewer)
);
stackPane.getChildren().add(swingNode);
} catch (DRException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
System.out.println("Hello Main");
try{
launch(args);
}
catch (Exception e){
e.printStackTrace();
}
}
}
DemoPOJO.java
package demo;
public class DemoPOJO {
String name;
String city;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
FXMLJavaFXJasperReportsDemo.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="561.0" prefWidth="745.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="demo.JavaFxJasperReportsDemo">
<children>
<Label layoutX="345.0" layoutY="24.0" text="Java FX Demo Application" />
<StackPane fx:id="stackPane" layoutX="14.0" layoutY="120.0" prefHeight="392.0" prefWidth="722.0" />
<Button layoutX="62.0" layoutY="68.0" mnemonicParsing="false" onAction="#loadReport" text="Load Report" />
</children>
</AnchorPane>
我正在使用的依赖项是:
<dependency>
<groupId>net.sourceforge.dynamicreports</groupId>
<artifactId>dynamicreports-core</artifactId>
<version>6.1.0</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11-ea+24</version>
</dependency>
输出量
我只是在投票,但没人给我答案。我非常渴望得到这个问题的任何解决方案。
—
Satish Pahuja,
并添加所有相关标签..也许来自秋千/
—
jasperreport
嗨,我使用来运行该程序,
—
Vall0n
jbsdk11b125_osx_x64
但无法重现该问题。它直接显示完整的内容。虽然我收到警告,通过版本10.0.2-internal的JavaFX运行时使用版本11.0.1的JavaFX API加载FXML文档
1)也可能是与图形驱动程序有关的问题。某些属性作为docs.oracle.com/en/java/javase/11/troubleshoot/…进行故障诊断的起点。2)您是否尝试过更高版本的
—
优
org.openjfx:javafx-swing
,例如11
?3)使用Java 11.0.5,Maven 3.6.2和插件,org.openjfx:javafx-maven-plugin:0.0.4
它可以正常工作而不会出现渲染问题(单击Load Report
按钮后显示报告)。该应用程序从开始mvn clean javafx:run
。