Reputation: 1468
Problem
I have a decent sized javaFX window that appears to work perfectly well, until i resize any window in the application. After the resize all components that have a drop-down or similar action (ie. Menu
, ComboBox
, TabPane
) become horribly slow.
Cause
I have narrowed the problem down to a progress bar, if i remove the progress bar from the scene i can resize the window(s) as much as i want, if i add it then any window resize and they start to become unresponsive for about half a second; sometimes as much as two seconds if i do a lot of resizing.
The window
A view of the window so that you can see all the components.
I can't add all the window code as its simply way too much to post.
Class with the progress bar
/**
* 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
}
}
Additional information
Most of the visible components on the window (ie. TableView
, ToolBar
, ListView
) are implementations. I doubt this is the problem
A lot of the widely used components such as Buttons
and Labels
are implementations that implement an interface that allows them to use a key that then gets the key value from a language file for its text. This doesn't do much on the rendering side nor is it called very often so i also doubt this is the problem.
The window starts up rather fast (less than a second).
I have a gaming pc so my hardware should not be a problem.
Java version: 1.8.0_40 (build 1.8.0_40-b25) 64-Bit
I suppose what i'm asking here is has any body else has this problem and if so how did you fix it?
Do you know what the problem could be? I don't think this is a bug as google doesn't have any/many results on it.
Any help would be appreciated as I'm completely stuck here.
An mcve that reproduces the results
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);
}
}
}
Click on the 'File' Menu and scroll through the items before and after resizing the window.
Upvotes: 2
Views: 1031
Reputation: 5123
The problem seems to be related to this bug:
[Windows] Very poor performance of application (or Menus) when using an Animation.
As a workaround, run the program with -Dprism.vsync=false
or -Dprism.order=sw
as VM argument.
Upvotes: 3