本文整理匯總了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;
}
示例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();
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}