当前位置: 首页>>代码示例>>Java>>正文


Java ChoiceBox.setConverter方法代码示例

本文整理汇总了Java中javafx.scene.control.ChoiceBox.setConverter方法的典型用法代码示例。如果您正苦于以下问题:Java ChoiceBox.setConverter方法的具体用法?Java ChoiceBox.setConverter怎么用?Java ChoiceBox.setConverter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javafx.scene.control.ChoiceBox的用法示例。


在下文中一共展示了ChoiceBox.setConverter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createParkingNumberChoiceBox

import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
private ChoiceBox<Parking> createParkingNumberChoiceBox() {
    ChoiceBox<Parking> parkingNumberChoiceBox = new ChoiceBox<>();
    parkingNumberChoiceBox.setPrefWidth(150);

    parkingNumberChoiceBox.setConverter(new StringConverter<Parking>() {
        @Override
        public String toString(Parking object) {
            return "(" + object.getId() + ") " + object.getName();
        }

        @Override
        public Parking fromString(String string) {
            Integer id = Integer.valueOf(string.substring(1, string.indexOf(')')));

            try {
                return ParkingApplicationManager.getInstance().getParkingById(id);
            } catch (ParkingNotPresentException e) {
                new Alert(Alert.AlertType.ERROR, "Vous avez sélectionné un parking inexistant. \n" + e);
            }
            return null;
        }
    });

    return parkingNumberChoiceBox;
}
 
开发者ID:SKNZ,项目名称:LesPatternsDuSwag,代码行数:26,代码来源:ChangeParkingStage.java

示例2: start

import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {

	VBox vbox = new VBox();
	vbox.setPadding(new Insets(10));
	vbox.setAlignment(Pos.CENTER);
	vbox.setSpacing(10);
	
	Label label = new Label("Make Yes/No Selection");
	
	ChoiceBox<Pair<String, String>> cb = new ChoiceBox<>();
	cb.setItems( Constants.LIST_YES_NO );
	cb.setConverter( new PairStringConverter() );
	cb.setValue( Constants.PAIR_NO );
	
	Label labelOpt = new Label("Make Yes/No Selection (Optional)");

	ChoiceBox<Pair<String, String>> cbOpt = new ChoiceBox<>();
	cbOpt.setItems( Constants.LIST_YES_NO_OPT );
	cbOpt.setConverter(new PairStringConverter(true) );
	cbOpt.setValue( Constants.PAIR_NULL );
	
	Button b = new Button("Save");
	b.setOnAction( (evt) -> 
		System.out.println("Selections - yes/no was '" + cb.getValue() + "' and yes/no/opt was '" + cbOpt.getValue() + "'")
	);
	
	vbox.getChildren().addAll(label, cb, labelOpt, cbOpt, b);
	
	Scene scene = new Scene(vbox);
	
	primaryStage.setTitle("Choice Box Demo");
	primaryStage.setHeight(200);
	primaryStage.setWidth(300);
	primaryStage.setScene( scene );
	primaryStage.show();
}
 
开发者ID:bekwam,项目名称:examples-javafx-repos1,代码行数:38,代码来源:ChoiceBoxDemo.java

示例3: buildDynamicSelectComponent

import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
private Node buildDynamicSelectComponent(ConfigNode node, String settingName, Serializable value) {
    try {
        DynamicSelection sel = (DynamicSelection) node.subject.getClass().getField(settingName).get(node.subject);
        ChoiceBox widget = new ChoiceBox(FXCollections.observableList(new ArrayList(sel.getSelections().keySet())));
        widget.setMinWidth(175.0);
        widget.setConverter(new StringConverter() {
            @Override
            public String toString(Object object) {
                return (String) sel.getSelections().get(object);
            }
            
            @Override
            public Object fromString(String string) {
                return sel.findValueByMatch(string);
            }
        });
        Object selected = value == null ? null : widget.getConverter().fromString(String.valueOf(value));
        if (selected == null) {
            widget.getSelectionModel().selectFirst();
        } else {
            widget.setValue(selected);
        }
        widget.valueProperty().addListener((Observable e) -> {
            node.setFieldValue(settingName, widget.getConverter().toString(widget.getValue()));
        });
        return widget;
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
        Logger.getLogger(ConfigurationUIController.class.getName()).log(Level.SEVERE, null, ex);
        return null;
    }
}
 
开发者ID:badvision,项目名称:jace,代码行数:32,代码来源:ConfigurationUIController.java

示例4: toolbarControlsFactory

import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
@Override
public List<Node> toolbarControlsFactory() {
    List<Node> controls = super.toolbarControlsFactory();

    CheckBox ellipsesCheckBox = new CheckBox("Ellipses");
    ellipsesCheckBox.setSelected(true);
    ellipsesCheckBox.setOnAction(mouseEvent -> {
        plot.setProperty(ELLIPSES, ellipsesCheckBox.isSelected());
    });
    
    ChoiceBox<SigmaPresentationModes> uncertaintyChoiceBox = new ChoiceBox<>(FXCollections.observableArrayList(SigmaPresentationModes.values()));
    uncertaintyChoiceBox.setValue(SigmaPresentationModes.TWO_SIGMA_ABSOLUTE);
    uncertaintyChoiceBox.setConverter(new StringConverter<SigmaPresentationModes>() {
        @Override
        public String toString(SigmaPresentationModes object) {
            return object.getDisplayName();
        }

        @Override
        public SigmaPresentationModes fromString(String string) {
            return null;
        }
    });
    uncertaintyChoiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<SigmaPresentationModes>() {
        @Override
        public void changed(ObservableValue observable, SigmaPresentationModes oldValue, SigmaPresentationModes newValue) {
            plot.setProperty(UNCERTAINTY, newValue.getSigmaMultiplier());
        }
    });

    ColorPicker ellipsesColorPicker = new ColorPicker(Color.RED);
    ellipsesColorPicker.setStyle(COLORPICKER_CSS_STYLE_SPECS);
    ellipsesColorPicker.setPrefWidth(100);
    ellipsesColorPicker.setOnAction(mouseEvent -> {
        // to satisfy D3
        plot.setProperty(ELLIPSE_FILL_COLOR, ellipsesColorPicker.getValue().toString().substring(0, 8).replaceAll("0x", "#"));
    });

    CheckBox concordiaLineCheckBox = new CheckBox("Concordia");
    concordiaLineCheckBox.setSelected(true);
    concordiaLineCheckBox.setOnAction(mouseEvent -> {
        plot.setProperty(CONCORDIA_LINE, concordiaLineCheckBox.isSelected());
    });

    CheckBox allSelectedCheckBox = new CheckBox("Select All");
    allSelectedCheckBox.setSelected(true);
    allSelectedCheckBox.setOnAction(mouseEvent -> {
        setSelectedAllData(allSelectedCheckBox.isSelected());
    });

    CheckBox regressionUnctEnvelopeCheckBox = new CheckBox("2D Regression Unct");
    regressionUnctEnvelopeCheckBox.setSelected(false);
    regressionUnctEnvelopeCheckBox.setOnAction(mouseEvent -> {
        plot.setProperty(REGRESSION_ENVELOPE, regressionUnctEnvelopeCheckBox.isSelected());
    });

    CheckBox regressionCheckBox = new CheckBox("2D Regression");
    regressionCheckBox.setSelected(false);
    regressionUnctEnvelopeCheckBox.setDisable(true);
    regressionCheckBox.setOnAction(mouseEvent -> {
        boolean isRegression = regressionCheckBox.isSelected();
        plot.setProperty(REGRESSION_LINE, isRegression);
        regressionUnctEnvelopeCheckBox.setDisable(!isRegression);
    });

    controls.add(ellipsesCheckBox);
    controls.add(uncertaintyChoiceBox);
    controls.add(ellipsesColorPicker);
    controls.add(allSelectedCheckBox);
    controls.add(concordiaLineCheckBox);
    controls.add(regressionCheckBox);
    controls.add(regressionUnctEnvelopeCheckBox);

    return controls;
}
 
开发者ID:CIRDLES,项目名称:Squid,代码行数:76,代码来源:TopsoilPlotWetherill.java

示例5: getPlayerInformationForm

import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
/**
 * Creates and returns the created form containing the fields about a player
 *
 * @param i The number of the player
 *
 * @return the form containing the fields that can be inputted about the player
 */
protected HBox getPlayerInformationForm(int i) {
    ResourceBundle i18nMessages = this.scrabble.getI18nMessages();

    HBox playerInformationHBox = new HBox();
    playerInformationHBox.getStyleClass().add("player");

    TextField playerNameTextField = new TextField(this.scrabble.getI18nMessages().getString("player") + " " + (i + 1));
    playerNameTextField.textProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue.length() > NewGameController.PLAYER_NAME_MAX_CHARACTERS) {
            playerNameTextField.setText(newValue.substring(0, NewGameController.PLAYER_NAME_MAX_CHARACTERS));
        }
    });

    CheckBox playerIsHumanCheckBox = new CheckBox(this.scrabble.getI18nMessages().getString("isPlayerHuman"));

    ChoiceBox<Short> levelChoiceBox = new ChoiceBox<>();
    List<Short> levels = Arrays.asList(ArtificialIntelligencePlayerInterface.LEVEL_VERY_EASY,
            ArtificialIntelligencePlayerInterface.LEVEL_EASY,
            ArtificialIntelligencePlayerInterface.LEVEL_MEDIUM,
            ArtificialIntelligencePlayerInterface.LEVEL_HARD,
            ArtificialIntelligencePlayerInterface.LEVEL_VERY_HARD);

    levelChoiceBox.getItems().addAll(levels);
    levelChoiceBox.setValue(levels.get(2));
    levelChoiceBox.setConverter(new StringConverter<Short>() {
        @Override
        public String toString(Short object) {
            return i18nMessages.getString("artificialIntelligenceLevels." + object.toString());
        }

        @Override
        public Short fromString(String string) {
            return null;
        }
    });

    levelChoiceBox.disableProperty().bind(playerIsHumanCheckBox.selectedProperty());

    playerInformationHBox.getChildren().addAll(playerNameTextField, playerIsHumanCheckBox, levelChoiceBox);

    return playerInformationHBox;
}
 
开发者ID:Chrisp1tv,项目名称:ScrabbleGame,代码行数:50,代码来源:NewGameController.java

示例6: MnemonicsScene

import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public MnemonicsScene() {
    super(box, 700, 400);
    Utils.addBrowser(this);

    final VBox object_box = new VBox(5);
    object_box.setMinWidth(200);
    final VBox control_box = new VBox(5);
    control_box.setMinWidth(300);
    ChoiceBox<ControlsFactory> choice = new ChoiceBox<ControlsFactory>();
    choice.setConverter(new StringConverter<ControlsFactory>() {
        @Override
        public String toString(ControlsFactory cl) {
            //return cl.getControlClass().getSimpleName();
            return cl.toString();
        }
        @Override
        public ControlsFactory fromString(String string) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    });
    for (ControlsFactory factory : ControlsFactory.filteredValues()) {
        final Class controlClass = factory.getControlClass();
        if (Labeled.class.isAssignableFrom(controlClass)) {
            choice.getItems().add(factory);
        }
    }
    choice.valueProperty().addListener(new ChangeListener<ControlsFactory>() {
        public void changed(ObservableValue<? extends ControlsFactory> ov, ControlsFactory t, ControlsFactory t1) {
            object_box.getChildren().clear();
            final Labeled node = (Labeled)t1.createNode();
            node.setId(LABELED_ID);
            node.setText("_" + node.getText());
            object_box.getChildren().add(node);
            if (grid != null) {
                control_box.getChildren().remove(grid);
            }
            grid = new PropertyCheckingGrid(node) {
                @Override
                protected boolean checkMethod(Object obj, Method m) {
                    return m.getDeclaringClass().equals(Labeled.class) && m.getName().contains("mnemonic");
                }
            };
            control_box.getChildren().add(grid);
        }
    });

    control_box.getChildren().add(choice);

    box.getChildren().addAll(object_box, control_box);
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:51,代码来源:MnemonicsApp.java


注:本文中的javafx.scene.control.ChoiceBox.setConverter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。