JavaFX ComboBox not responding on Windows 10

本小妞迷上赌 提交于 2019-11-28 16:47:11

问题


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();

}

}

回答1:


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.




回答2:


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();
    }
});



回答3:


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).



回答4:


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.




回答5:


My late two cents, but I do confirm that

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

(As posted by @PingZing)

Did fix the same problem on my app. The touch ability was simply given by....

Pen 'n touch Wacom bamboo create tablet

That is giving Windows 10 touch capabilities



来源:https://stackoverflow.com/questions/31786980/javafx-combobox-not-responding-on-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!