Does something like this work:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package util.settings;
import com.jme3.system.AppSettings;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class FXSettingsDialog extends Application {
public boolean canStart = false;
public boolean isCancelled = false;
public VBox main;
public List<HBox> horizontals;
public Group userGroup;
public StackPane root;
public Map<Dimension, Dimension> dimensions;
public String title = "Game";
public Image image;
public List<CheckBox> checkboxes;
public List<ComboBox> dropdowns;
public com.jme3.system.AppSettings appSettings;
public Map<Object, Object> customSettings;
public FXSettingsDialog(String[] args) {
this(args, null);
}
public FXSettingsDialog(String[] args, Group userDefined) {
this.userGroup = userDefined;
launch(args);
}
@Override
public void start(Stage primaryStage) {
dimensions = new HashMap<>();
//Put width and height dimensions
//720p to 480p
dimensions.put(new Dimension(1280, 720), new Dimension(640, 480));
dimensions.put(new Dimension(1024, 768), new Dimension(640, 480));
dimensions.put(new Dimension(1024, 1024), new Dimension(640, 480));
//1080p to 720p
dimensions.put(new Dimension(1440, 900), new Dimension(1280, 720));
dimensions.put(new Dimension(1680, 1050), new Dimension(1280, 720));
dimensions.put(new Dimension(1920, 1080), new Dimension(1280, 720));
dimensions.put(new Dimension(1920, 1200), new Dimension(1280, 720));
//1440p to 1080p
dimensions.put(new Dimension(2376, 1824), new Dimension(1920, 1080));
dimensions.put(new Dimension(2560, 1440), new Dimension(1920, 1080));
dimensions.put(new Dimension(2560, 1440), new Dimension(1920, 1080));
dimensions.put(new Dimension(2048, 1920), new Dimension(1920, 1080));
dimensions.put(new Dimension(7680, 4320), new Dimension(3840, 2160));
//4K to 1440p
dimensions.put(new Dimension(3840, 2160), new Dimension(2560, 1440));
root = new StackPane();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
primaryStage.setScene(new Scene(root, dimensions.get(screenSize).getWidth(), dimensions.get(screenSize).getHeight()));
appSettings = new AppSettings(true);
customSettings = new HashMap<>();
//User has not defined an alternate UI, loading defaults
if(userGroup == null) {
main = new VBox();
horizontals = new ArrayList<>();
root.getChildren().add(main);
ImageView imageView = new ImageView(image);
main.getChildren().add(imageView);
{//Checkboxes
checkboxes = new ArrayList<>();
checkboxes.add(new ActionCheckBox("Fullscreen",
new EventHandler<ActionEvent> (){
@Override
public void handle(ActionEvent e){
appSettings.put("Fullscreen", !(Boolean)appSettings.get("Fullscreen"));
}
}
));
checkboxes.add(new ActionCheckBox("V-Sync (Reduces Screen Tearing)",
new EventHandler<ActionEvent> (){
@Override
public void handle(ActionEvent e){
appSettings.put("vsync", !(Boolean)appSettings.get("vsync"));
}
}));
checkboxes.add(new ActionCheckBox("Gamma Correction (Makes Colors More Accurate)",
new EventHandler<ActionEvent> (){
@Override
public void handle(ActionEvent e){
appSettings.put("gamma", !(Boolean)appSettings.get("gamma"));
}
}));
HBox checkboxHBox = new HBox();
checkboxHBox.getChildren().addAll(checkboxes);
horizontals.add(checkboxHBox);
}
{//Dropdowns
dropdowns = new ArrayList<>();
dropdowns.add(new ActionComboBox<Dimension>(dimensions.keySet(), new Action(){
@Override
public void onAction(Object object){
Dimension d = (Dimension) object;
appSettings.put("width", d.getWidth());
appSettings.put("height", d.getHeight());
}
}));
dropdowns.add(new ActionComboBox<String>(Arrays.asList("30", "60", "120"), new Action(){
@Override
public void onAction(Object e){
appSettings.put("refreshrate", Integer.parseInt((String)e));
}
}));
dropdowns.add(new ActionComboBox<String>(Arrays.asList("16", "24", "32"), new Action(){
@Override
public void onAction(Object e){
appSettings.put("colorbit", Integer.parseInt((String)e));
}
}));
dropdowns.add(new ActionComboBox<String>(Arrays.asList("0", "4", "8", "16"), new Action(){
@Override
public void onAction(Object e){
appSettings.put("antialias", Integer.parseInt((String)e));
}
}));
HBox dropbox = new HBox();
dropbox.getChildren().addAll(dropdowns);
horizontals.add(dropbox);
}
main.getChildren().addAll(horizontals);
HBox buttons = new HBox();
Button start = new Button("Start");
start.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent e){
canStart = true;
}
});
Button cancel = new Button("Cancel");
start.setOnAction(new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent e){
isCancelled = true;
}
});
buttons.getChildren().add(start);
buttons.getChildren().add(cancel);
}else{
root.getChildren().add(userGroup);
}
primaryStage.show();
}
public static class ActionCheckBox extends CheckBox {
public ActionCheckBox(String label, EventHandler<ActionEvent> onAction) {
super(label);
this.setOnAction(onAction);
}
}
public static class ActionComboBox<T> extends ComboBox<T> {
public Action action;
public ActionComboBox(Collection<T> options, Action onAction) {
super();
super.getItems().addAll(options);
this.action = onAction;
this.valueProperty().addListener(new ChangeListener<T>() {
@Override
public void changed(ObservableValue<? extends T> ov, T t, T t1) {
action.onAction(t1);
}
});
}
}
public static interface Action {
public abstract void onAction(Object object);
}
}