2

So my program that's been using ComboBox has stopped working. Before i updated my jdk from 8u20 to 8u50, now when the same program is run without any changes to it, if the ComboBox is selected without tabbing to it first, it causes the program to freeze up and then crash.

I've only seen this in one other spot on the web after searching and the only way to prevent the crash is to press tab until the combobox is selected and use the arrow keys to select.

Has anyone else heard of this?

Here is an example that you can easily run if you copy paste these two classes and run main.

MAIN CLASS:

import javafx.application.Application;
import javafx.stage.Stage;

import java.util.ArrayList;

/**
 * Created by Josh on 19/8/2015.
 */
public class Main extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {

        ArrayList<String> options = new ArrayList<String>();
        options.add("Apple");
        options.add("Orange");
        options.add("Pear");

        String result = Selection_Dialog.show(options, "Orange");

    }

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

ComboBox Class:

import com.sun.glass.ui.Screen;
import javafx.event.*;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.text.TextAlignment;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.awt.*;

import java.util.ArrayList;

class Selection_Dialog {

    //Window Properties
    private static final String TITLE = "Selection Dialog";
    private static String DEFAULT_MESSAGE = "";
    private static int DEFAULT_WIDTH = 400;
    private static int DEFAULT_HEIGHT = 250;
    private static Point DEFAULT_POSITION = new Point();

    //Window Components
    private static Stage stage;
    private static javafx.scene.control.Label messageLabel;
    private static javafx.scene.control.Button okButton;
    private static ComboBox selector;

    //Show Window Popup
    public static String show(ArrayList<String> options, String initial) {
        return show(options, initial, DEFAULT_MESSAGE, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_POSITION);
    }
    public static String show(ArrayList<String> options, String initial, String message) {
        return show(options, initial, message, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_POSITION);
    }
    public static String show(ArrayList<String> options, String initial, String message, Point position) {
        return show(options, initial, message, DEFAULT_WIDTH, DEFAULT_HEIGHT, position);
    }
    public static String show(ArrayList<String> options, String initial, String message, int width, int height) {
        return show(options, initial, message, width, height, DEFAULT_POSITION);
    }
    public static String show(ArrayList<String> options, String initial, String message, int width, int height, Point position) {

        //Setup Properties
        stage = new Stage();
        BorderPane root = new BorderPane();
        stage.initStyle(StageStyle.UTILITY);
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.setScene(new Scene(root, width, height));
        stage.setTitle(TITLE);
        stage.setResizable(false);
        stage.setOnCloseRequest(new EventHandler() {
            @Override
            public void handle(javafx.event.Event event) {
                event.consume();
            }
        });
        if(position == DEFAULT_POSITION){
            int x, y;
            x = Screen.getMainScreen().getWidth()/2;
            y = Screen.getMainScreen().getHeight()/2;
            x = x - width/2;
            y = y - height/2;
            position = new Point(x, y);
        }
        stage.setX(position.getX());
        stage.setY(position.getY());


        //Create Components
        messageLabel = new javafx.scene.control.Label(message);
        okButton = new javafx.scene.control.Button("Ok");
        selector = new ComboBox();
        selector.getItems().addAll(options);
        if(options.size() > 0){
            if(initial == null){
                selector.getSelectionModel().select(0);
            }else if(options.contains(initial)){
                selector.getSelectionModel().select(initial);
            }else{
                selector.getSelectionModel().select(0);
            }

        }

        //Align Components
        root.setAlignment(messageLabel, Pos.CENTER);
        root.setAlignment(okButton, Pos.CENTER);
        messageLabel.setTranslateY(15);
        okButton.setTranslateY(-25);
        messageLabel.setTextAlignment(TextAlignment.CENTER);
        messageLabel.setWrapText(true);

        //Add Components
        root.setBottom(okButton);
        root.setTop(messageLabel);
        root.setCenter(selector);

        //Add Listeners

        okButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                stage.close();
            }
        });

        //Show Window
        stage.showAndWait();

        return selector.getSelectionModel().getSelectedItem().toString();
    }

}

I made the ComboBox class so i can easily get selection dialogs from user in future projects. It worked fine before, maybe there is something wrong with it?

Josh
  • 187
  • 1
  • 1
  • 9
  • never seen such behaviour (in the ea versions of 8u60 - there is no u50, or is there?) Please show a SSCCE that demonstrates the problem so I can try to reproduce it – kleopatra Aug 19 '15 at 08:46
  • I added the class i am using to create the combobox and and example Main which just puts 3 options in ComboBox the and stores result in a string. – Josh Aug 20 '15 at 01:38
  • And sorry i meant it was update 51 – Josh Aug 20 '15 at 01:40
  • NEW DISCOVERY: I replaced every instance of "ComboBox" and replaced it with "ChoiceBox" and now it works flawlessly. This is really weird. Choice boxes are lame though compared to combobox's :( – Josh Aug 20 '15 at 02:32
  • 1
    hmm ... can't reproduce (with 8u60b18) - might be too old (predates u51 by a couple of weeks), will update to the final 8u60 and try again. BTW: a) mixing awt.Point into an fx app isn't a good idea (doesn't really hurt here, as you only use its field) b) `Screen.getMainScreen()` doesn't compile (replacing by getPrimary and using its visualBounds does compile) - might be either new api (not aware of it) or some slight mixup of environments, can't tell. – kleopatra Aug 20 '15 at 09:05
  • updated to u60 and tried it again and im still getting the same error. It might be a graphics card error or something i guess. WEIRD. I noticed in updat4e 60 my resolutions have changed... Did they add a new scaling resolution feature to javafx or something? – Josh Aug 20 '15 at 20:16
  • copying the deleted answer by @kaiwa: _Same problem was reported here [JavaFX Windows 10 ComboBox error](http://stackoverflow.com/questions/31786980/javafx-windows-10-combobox-error) It happens both in Java8u51 and in Java8u60 on my atom tablet. Intel GPU may be the cause._ – kleopatra Aug 26 '15 at 13:18
  • meanwhile, updated to the u60 release - still can't reproduce on win7/vista. So might a bug that's highly environment dependent. – kleopatra Aug 26 '15 at 13:20
  • Same problem here with Java 8u60 and Windows 10. Tested with Java 7u80: no problems. Select another Node (eg. a button), click on the ComboBox, and it crashes. Thanks for mentioning the ChoiceBox btw. – SWdV Aug 29 '15 at 20:48

0 Answers0