后,我有一个看起来很好的工作,直到我调整应用程序窗口的任何一个中型的JavaFX窗口。调整大小后,所有具有下拉或类似操作的组件(即Menu
,ComboBox
,TabPane
)变得非常缓慢。
原因
我已经缩小的问题降到一个进度条,如果我删除从现场的进度条,我可以调整窗口的大小(S),就像我想,如果我添加它,然后任何窗口调整大小,并且它们在大约半秒时间内开始变得无响应;有时甚至会有两秒钟,如果我做了很多调整大小。
窗口
窗口的视图,以便您可以看到所有的组件。
我不能添加的所有窗口的代码作为其根本太多张贴。
类与窗口上的进度条
/**
* 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
}
}
附加信息
大部分可见光成分的(即
TableView
,ToolBar
,ListView
)是实施方式。我怀疑这是问题许多广泛使用的组件,如
Buttons
和Labels
是实现一个接口,允许他们使用一个密钥,然后从其文本的语言文件中获取键值的实现。这在渲染方面没有太多的工作,也不经常被调用,所以我也怀疑这是问题所在。窗口启动相当快(不到一秒)。
我有一台游戏PC,所以我的硬件不应该是一个问题。
Java版本:1.8.0_40(建1.8.0_40-B25)64位
我想我要问这里有什么身体人有这个问题,如果是的话,你是如何解决它的?
你知道这个问题可能是什么吗?我不认为这是一个错误,因为谷歌没有任何/许多结果。
任何帮助将不胜感激,因为我完全卡在这里。
再现结果
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);
}
}
}
单击“文件”菜单和之前和调整窗口后,在项目之间滚动的MCVE。
有两件事情我不清楚:1)你的'addItems()'方法创建一个'Region',但从来没有使用它。 2)getItems()和add(Node)方法在结果中会发生什么。请将该代码添加到问题中。 – hotzst
您可能希望为此创建[mcve](http://stackoverflow.com/help/mcve)(如果您成功创建一个,您将更有可能获得帮助)。 – jewelsea
@hotzst该地区已添加。 'this.getItems()。add(r);'将该区域添加到工具栏中的组件列表中。 getItems()方法是ToolBar的一部分,它是工具栏中要显示的组件上的一个ObservableList。 –