简体   繁体   English

从JavaFX 2.2到JavaFX8

[英]From JavaFX 2.2 to JavaFX8

I have made an application using JavaFX 2.2 and want to switch to JavaFX 8. Using JavaFX2.2 my application looks like this: 我已经使用JavaFX 2.2创建了一个应用程序,并希望切换到JavaFX8。使用JavaFX2.2,我的应用程序如下所示:

JavaFX 2.2

When using JavaFX 8 without changing any source code it looks like this: 当使用JavaFX 8而不更改任何源代码时,它看起来像这样:

JavaFX8

With JavaFX8 some nodes are not shown at all (eg Criterion 1) and sometimes appear after clicking randomly on the scrollpane. 使用JavaFX8,某些节点根本不会显示(例如,标准1),有时会在随机单击滚动窗格后出现。 In addition the nodes have an incorrect size (compare Step 1 and the small little dot). 另外,节点的大小不正确(比较步骤1和小的小点)。 Another problem is that when performing actions such as adding nodes the application lags heavily in JavaFX8. 另一个问题是,当执行诸如添加节点之类的操作时,应用程序在JavaFX8中严重滞后。

Unfortunately I do not get any error messages at all and I have almost no clue what I have to fix in order to get the application working in JavaFX8. 不幸的是,我根本没有收到任何错误消息,而且我几乎不知道要使该应用程序在JavaFX8中运行必须修复的内容。 Any help/ideas/hints would be greatly appreciated. 任何帮助/想法/提示将不胜感激。

Possible issues (?): 可能的问题(?):

  • I have used Platform.runLater() very often in my application. 我在应用程序中经常使用Platform.runLater()。 Has this perhaps changed in JavaFX 8? 这在JavaFX 8中可能有所改变吗?
  • in JavaFX2.2 the size of a node (eg stackpane containing text) was automatically computed after adding it to the scroll pane. 在JavaFX2.2中,将节点添加到滚动窗格后,会自动计算节点的大小(例如,包含文本的堆栈窗格)。 Let's say I add a node with position x and y. 假设我添加了一个位置为x和y的节点。 Only after JavaFX has drawn it I can get its height and width (boundsInParent.getHeight()). 只有在绘制JavaFX之后,我才能获得其高度和宽度(boundsInParent.getHeight())。 This is also the reason why I often used Platform.runLater() in order to layout the nodes. 这也是为什么我经常使用Platform.runLater()来布局节点的原因。 Has this behaviour changed in JavaFX 8? JavaFX 8中的这种行为是否已更改?

EDIT: The "bug" is connected with css styling. 编辑:“错误”与CSS样式相关。 If I remove the stylesheets that are added to the nodes everything works fine (except the styling of the nodes of course). 如果我删除添加到节点的样式表,则一切正常(当然,除了节点的样式外)。 In particular the commands I have to remove are of the following form: 特别是我必须删除的命令具有以下形式:

getStylesheets().add(ClassName.class.getResource("CSSFile.css").toExternalForm()); 。getStylesheets()添加(ClassName.class.getResource( “CSSFile.css”)toExternalForm());

I have identified the error: I had one negative value within my css stylesheet (which was used for the nodes). 我发现了错误:在CSS样式表(用于节点)中有一个负值。 Removing that value made it work like in JavaFX 2.2. 删除该值使它像在JavaFX 2.2中一样工作。 To be precise I had to change the following: 确切地说,我必须更改以下内容:

-fx-border-width: 5 -1 0 5 ;

to

-fx-border-width: 5 0 0 5 ;

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

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