简体   繁体   English

寻找将FXML与Java 7结合使用的指南

[英]Looking for a guide using FXML with Java 7

I need to target Java 7 and would like to use JavaFX and FXML on that project. 我需要针对Java 7,并希望在该项目上使用JavaFX和FXML。 We have some working code for Java 8 and it would save an immense amount of time if we can retro-fit those modules to Java 7. 我们有一些适用于Java 8的代码,如果我们可以将这些模块改装为Java 7,则可以节省大量时间。

I'm posting because I'm getting compile errors on the first attempt. 我发布是因为第一次尝试时出现编译错误。 In the first instance, I can't find the @FXML annotation, package: 在第一个实例中,我找不到@FXML注释包:

  • import javafx.fxml.FXML 导入javafx.fxml.FXML

In Java 8 JDK. 在Java 8 JDK中。 However that just a for instance example. 但是,这只是一个例子。

I was hoping to find Java 7 JDK JavaFX documentation. 我希望找到Java 7 JDK JavaFX文档。 The searches and tutorials seem to be either aimed at Java 8 and/or not about things that work differently between the two 搜索和教程似乎是针对Java 8的,和/或不是针对两者之间工作不同的事物的

The solution is some documentation describing what's different in Java 8 JDK JavaFX to Java 7's JavaFS JDK? 解决方案是一些文档,描述Java 8 JDK JavaFX与Java 7的JavaFS JDK有何不同? Google isn't giving me much satisfaction and most of the Stackoverflow questions are going the other way. Google给我的满意度不高,大多数Stackoverflow问题正朝着相反的方向发展。 I suppose it is rare for someone to ask how to go back a version. 我想很少有人问如何返回一个版本。 Any one seen, know of or some release notes on code differences (or a migration guide??). 任何人都可以看到,知道或有一些有关代码差异的发行说明(或迁移指南?)。 Many thanks in advance. 提前谢谢了。

JavaFX 2 is the version of JavaFX included in Java 7. All of the Oracle JavaFX 2 documentation is currently available online (it may be removed at some time in the future in the same way JavaFX 1 documentation was removed). JavaFX 2是Java 7中包含的JavaFX的版本。所有Oracle JavaFX 2文档当前都可以在线获得 (将来可能会以与删除JavaFX 1文档相同的方式删除)。 FXML is supported in Java 7, there were no significant changes to FXML for Java 8, so any FXML specific information you read for Java 8 will also be relevant for Java 7. Java 7支持FXML,Java 8的FXML没有重大变化,因此您为Java 8阅读的所有FXML特定信息也将与Java 7相关。

You don't really need a backward migration guide I think (not that any such guide would exist anywhere anyway). 我认为您实际上并不需要向后迁移指南(反正任何地方都不会存在任何此类指南)。 You can just compile your program against the most recent version of Java 7 and fix any compile errors that occur by removing any lambda references and coding against the older API. 您可以仅针对最新版本的Java 7编译程序,并通过删除所有lambda引用并针对旧版API进行编码来修复发生的所有编译错误。 Unless you are using JavaFX 3D or printing or some such feature which was completely new in Java 8, I can't really see backward conversion being much of a problem or an extremely large task (90%+ of the public API will be unchanged). 除非您使用JavaFX 3D或打印或Java 8中全新的某些功能,否则我不会真正看到向后转换成为很大的问题或完成非常大的任务(90%以上的公共API将保持不变) 。

One reason you are getting compile errors such as class not found is because you need to explicitly add the JavaFX 2 runtime to the compile and runtime classpath (for Oracle Java 8, this requirement was removed). 出现未找到类之类的编译错误的原因之一是,因为您需要将JavaFX 2运行时显式添加到编译和运行时类路径中(对于Oracle Java 8,此要求已删除)。 See the answer to Compile code using JavaFX 2.0 (using command line) for more details. 有关更多详细信息,请参见使用JavaFX 2.0编译代码的答案(使用命令行)

I'd recommend against backporting code anyway as there were so many improvements in JavaFX 8 . 无论如何,我还是建议不要向后移植代码,因为JavaFX 8有很多改进 Also Java 7 has a limited support life. Java 7的支持寿命也很有限。 If you bundle your app as a self-contained application, then you have control of the Java runtime that the app runs on, so Java 8 would be an obvious choice for such a scenario. 如果将应用程序捆绑为独立的应用程序,则可以控制该应用程序在其上运行的Java运行时,因此对于这种情况,Java 8将是显而易见的选择。 But I guess you may have some constraint which forces you to code to Java 7 (which you don't need to outline here). 但是我想您可能会有一些约束,这些约束迫使您必须使用Java 7进行编码(此处无需概述)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM