JavaFX 进度条在调整大小后导致严重 window 滞后
JavaFX progress bar causes severe window lag after a resize
问题
我有一个大小适中的 javaFX window,它看起来运行良好,直到我在应用程序中调整任何 window 的大小。调整大小后,所有具有下拉或类似操作的组件(即 Menu
、ComboBox
、TabPane
)变得非常慢。
原因
我已经将问题缩小到进度条,如果我从场景中删除进度条,我可以根据需要调整 window(s) 的大小,如果我添加它,那么任何 window 调整大小,他们开始变得反应迟钝大约半秒钟;如果我进行大量调整,有时会长达两秒。
window
window 视图,以便您可以看到所有组件。
我无法将所有 window 代码添加到 post。
Class带进度条
/**
* The class that holds and displays the progress bar
*/
public class BottomToolBarImpl extends ToolBar {
/**
* The label that display the "Waiting for input" text at the bottom of the
* window
*
* The {@code LLabel()} class is a label that gets its text from a
* properties file
*/
private final Label text = new LLabel().setTextKey("waiting").register();
/**
* This is the progress bar itself that is causing the problem
*/
private final ProgressBar progressBar = new ProgressBar();
/**
* Constructs the tool bar and adds the components
*/
public BottomToolBarImpl() {
super();
addItems();
}
/**
* Adds the progress bar and label the this object
*/
private void addItems() {
Region r = new Region();
r.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(r, Priority.ALWAYS);
progressBar.setMinWidth(192);//This line has no effect on the performance
this.getItems().add(r);
this.getItems().add(text);
this.getItems().add(progressBar);//If i comment out this line then all works perfectly
}
}
附加信息
window(即 TableView
、ToolBar
、ListView
)上的大部分可见组件都是实现。我怀疑是这个问题
许多广泛使用的组件,例如 Buttons
和 Labels
都是实现接口的实现,该接口允许它们使用键,然后从中获取键值其文本的语言文件。这在渲染方面没有太大作用,也不是经常调用所以我也怀疑这是问题所在。
window 启动相当快(不到一秒)。
我有一台游戏电脑,所以我的硬件应该没有问题。
Java 版本:1.8.0_40(构建 1.8.0_40-b25)64 位
我想我在这里问的是有没有其他人有这个问题,如果有,你是如何解决的?
你知道可能是什么问题吗?我不认为这是一个错误,因为 google 没有 any/many 结果。
任何帮助将不胜感激,因为我完全被困在这里。
重现结果的 mcve
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Reproduce problem");
final StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 500, 400));
final VBox layout = new VBox(10);
layout.getChildren().addAll(new MenuImpl(), new ProgressToolBar());
root.getChildren().add(layout);
primaryStage.show();
}
private class ProgressToolBar extends ToolBar {
private final Label text = new Label("Random Text Here");
private final ProgressBar progressBar = new ProgressBar();
public ProgressToolBar() {
super();
addItems();
}
private void addItems() {
Region r = new Region();
r.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(r, Priority.ALWAYS);
progressBar.setMinWidth(192);
this.getItems().add(r);
this.getItems().add(text);
this.getItems().add(progressBar); //Still causes the problem
}
}
private class MenuImpl extends MenuBar {
public final Menu FILE = new Menu("File", null, new MenuItem("A"), new MenuItem("B"), new MenuItem("C"));
public MenuImpl() {
super();
this.getMenus().addAll(FILE);
}
}
}
单击 'File' 菜单并滚动浏览调整 window 大小前后的项目。
问题似乎与这个错误有关:
[Windows] Very poor performance of application (or Menus) when using an Animation.
作为变通方法,运行 以 -Dprism.vsync=false
或 -Dprism.order=sw
作为 VM 参数的程序。
问题
我有一个大小适中的 javaFX window,它看起来运行良好,直到我在应用程序中调整任何 window 的大小。调整大小后,所有具有下拉或类似操作的组件(即 Menu
、ComboBox
、TabPane
)变得非常慢。
原因
我已经将问题缩小到进度条,如果我从场景中删除进度条,我可以根据需要调整 window(s) 的大小,如果我添加它,那么任何 window 调整大小,他们开始变得反应迟钝大约半秒钟;如果我进行大量调整,有时会长达两秒。
window
window 视图,以便您可以看到所有组件。
我无法将所有 window 代码添加到 post。
Class带进度条
/**
* The class that holds and displays the progress bar
*/
public class BottomToolBarImpl extends ToolBar {
/**
* The label that display the "Waiting for input" text at the bottom of the
* window
*
* The {@code LLabel()} class is a label that gets its text from a
* properties file
*/
private final Label text = new LLabel().setTextKey("waiting").register();
/**
* This is the progress bar itself that is causing the problem
*/
private final ProgressBar progressBar = new ProgressBar();
/**
* Constructs the tool bar and adds the components
*/
public BottomToolBarImpl() {
super();
addItems();
}
/**
* Adds the progress bar and label the this object
*/
private void addItems() {
Region r = new Region();
r.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(r, Priority.ALWAYS);
progressBar.setMinWidth(192);//This line has no effect on the performance
this.getItems().add(r);
this.getItems().add(text);
this.getItems().add(progressBar);//If i comment out this line then all works perfectly
}
}
附加信息
window(即
TableView
、ToolBar
、ListView
)上的大部分可见组件都是实现。我怀疑是这个问题许多广泛使用的组件,例如
Buttons
和Labels
都是实现接口的实现,该接口允许它们使用键,然后从中获取键值其文本的语言文件。这在渲染方面没有太大作用,也不是经常调用所以我也怀疑这是问题所在。window 启动相当快(不到一秒)。
我有一台游戏电脑,所以我的硬件应该没有问题。
Java 版本:1.8.0_40(构建 1.8.0_40-b25)64 位
我想我在这里问的是有没有其他人有这个问题,如果有,你是如何解决的?
你知道可能是什么问题吗?我不认为这是一个错误,因为 google 没有 any/many 结果。
任何帮助将不胜感激,因为我完全被困在这里。
重现结果的 mcve
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Reproduce problem");
final StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 500, 400));
final VBox layout = new VBox(10);
layout.getChildren().addAll(new MenuImpl(), new ProgressToolBar());
root.getChildren().add(layout);
primaryStage.show();
}
private class ProgressToolBar extends ToolBar {
private final Label text = new Label("Random Text Here");
private final ProgressBar progressBar = new ProgressBar();
public ProgressToolBar() {
super();
addItems();
}
private void addItems() {
Region r = new Region();
r.setMaxWidth(Double.MAX_VALUE);
HBox.setHgrow(r, Priority.ALWAYS);
progressBar.setMinWidth(192);
this.getItems().add(r);
this.getItems().add(text);
this.getItems().add(progressBar); //Still causes the problem
}
}
private class MenuImpl extends MenuBar {
public final Menu FILE = new Menu("File", null, new MenuItem("A"), new MenuItem("B"), new MenuItem("C"));
public MenuImpl() {
super();
this.getMenus().addAll(FILE);
}
}
}
单击 'File' 菜单并滚动浏览调整 window 大小前后的项目。
问题似乎与这个错误有关:
[Windows] Very poor performance of application (or Menus) when using an Animation.
作为变通方法,运行 以 -Dprism.vsync=false
或 -Dprism.order=sw
作为 VM 参数的程序。