Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX ComboBox not responding on Windows 10

I recently upgraded to Windows 10 and JavaFX code which worked in Windows 8.1 appears to freeze up in 10. I've tracked the issue down to opening a ComboBox within a dialog. This appears to freeze any JavaFX program. Does anyone else have the same issue? (Windows 10 computers are still few and far between so would be good to confirm bug is indeed JavaFX issue)

I have attached example code below. The ComboBox in the main stage is fine but when I open a dialog and try and use the ComboBox there, the whole thing freezes. I'm using Java 8u51 in Eclipse 4.4.0

package javafxExamples;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class ComboErrorTest extends Application {

String[] list={"Jamie", "Arthur", "Gordon"};

private Stage stage;

public static void main(String[] args) {
    launch(args);
}


@Override
public void start(Stage stage) throws Exception {
    //create box in main stage.
    ComboBox<String> comboBox=new ComboBox<String>(); 
    for (int i=0; i<list.length; i++){
        comboBox.getItems().add(list[i]);
    }
    comboBox.getSelectionModel().select(list[0]);

    BorderPane pane = new BorderPane(comboBox);
    pane.setPrefSize(400, 250);

    //dialog bit
    List<String> choices = new ArrayList<>();
    choices.add("a");
    choices.add("b");
    choices.add("c");

    ChoiceDialog<String> dialog = new ChoiceDialog<>("b", choices);
    dialog.setTitle("Choice Dialog");
    dialog.setHeaderText("Look, a Choice Dialog");
    dialog.setContentText("Choose your letter:");


    Button dialogButton=new Button("Open Dialog...");
    dialogButton.setOnAction((action)->{
        // Traditional way to get the response value.
        Optional<String> result = dialog.showAndWait();
        if (result.isPresent()){
            System.out.println("Your choice: " + result.get());
        }
    });

    pane.setBottom(dialogButton);

    Scene scene = new Scene(pane);

    stage.setTitle("ComboError Demo");
    stage.setScene(scene);
    stage.show();

}

}
like image 709
macster110 Avatar asked Aug 03 '15 12:08

macster110


4 Answers

According to the bug report, a temporary workaround is setting the following system property:

java -Dglass.accessible.force=false ... 

or, in an application's code:

System.setProperty("glass.accessible.force", "false");

Or, alternately, "Run the Windows Narrator screen reader (with accessibility left enabled)".

The bug appears to have been introduced in JDK 8u40, and affects Windows 10 systems with a touchscreen installed and enabled.

Some quick testing seems to indicate that it solved the problem for me.

like image 147
PingZing Avatar answered Nov 09 '22 05:11

PingZing


As mentioned in other answers, this is likely an error to do with Intel graphics processors and it appears not to be solved by a driver update.

However, while this bug is hopefully being fixed, for now I recommend adding an event which focuses the combobox upon a mouse press and therefore solves the problem. Simply add the code below:

comboBox.setOnMousePressed(new EventHandler<MouseEvent>(){
    @Override
    public void handle(MouseEvent event) {
        comboBox.requestFocus();
    }
});
like image 44
Cryptoclysm Avatar answered Nov 09 '22 05:11

Cryptoclysm


Upgrading to JDK 8u72 or newer should fix the issue.

This was a known issue in JDK 8u40 affecting certain Windows 10 touchscreen computers. Clicking an out of focus ComboBox would cause programs to become unresponsive. The issue was resolved on September 17, 2015, meaning it shouldn't happen on any version after JDK 8u72.

If upgrading your JDK isn't an option, there are two known workarounds.

  1. Run your app with accessibility disabled by adding System.setProperty("glass.accessible.force", "false");
  2. Run the Windows Narrator screen reader (with accessibility left enabled).
like image 31
Stevoisiak Avatar answered Nov 09 '22 06:11

Stevoisiak


I am having the same problem with an Intel HD 4000.

I may have a solution though. I just replaced every usage of ComboBox in my application with ChoiceBox. It isn't ideal, but for small applications like mine, it might be the best option until Oracle, or Intel, gets their act together.

like image 41
Austin Lackey Avatar answered Nov 09 '22 07:11

Austin Lackey