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?