本文整理汇总了Java中javafx.scene.control.ChoiceBox.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java ChoiceBox.setValue方法的具体用法?Java ChoiceBox.setValue怎么用?Java ChoiceBox.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.ChoiceBox
的用法示例。
在下文中一共展示了ChoiceBox.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
@Override
public void start(Stage stage) {
Scene scene = new Scene(new Group());
scene.setFill(Color.ALICEBLUE);
stage.setScene(scene);
stage.show();
stage.setTitle("ChoiceBox Sample");
stage.setWidth(300);
stage.setHeight(200);
label.setFont(Font.font("Arial", 25));
label.setLayoutX(40);
final String[] greetings = new String[]{"Hello", "Hola", "Привет", "你好",
"こんにちは"};
final ChoiceBox cb = new ChoiceBox(FXCollections.observableArrayList(
"English", "Español", "Русский", "简体中文", "日本語")
);
cb.getSelectionModel().selectedIndexProperty().addListener(
(ObservableValue<? extends Number> ov,
Number old_val, Number new_val) -> {
label.setText(greetings[new_val.intValue()]);
});
cb.setTooltip(new Tooltip("Select the language"));
cb.setValue("English");
HBox hb = new HBox();
hb.getChildren().addAll(cb, label);
hb.setSpacing(30);
hb.setAlignment(Pos.CENTER);
hb.setPadding(new Insets(10, 0, 0, 10));
((Group) scene.getRoot()).getChildren().add(hb);
}
示例2: addEnumParameterHBox
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
/**
* creates a {@link javafx.scene.layout.HBox} with the information from the
* learning parameter if it is a {@link TerminationCriteria}
*
* @param param
* @param root
* @param position
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private void addEnumParameterHBox(LearningParameter param, GridPane root, int position) {
Label parameterLabel = new Label(param.getName());
ChoiceBox cb = new ChoiceBox();
cb.setItems(FXCollections.observableArrayList(getEnumArrayList((Class<Enum>) param.getClazz())));
cb.setValue(param.getValue());
cb.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Enum>() {
public void changed(ObservableValue ov, Enum value, Enum new_value ){
param.setValue(new_value.toString());
}
});
root.add(parameterLabel, 0, position);
root.add(cb, 1, position);
}
示例3: getSelectCOMPorts
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public static void getSelectCOMPorts(ChoiceBox selectPort)
{
String[] ports = SerialUtils.getOpenCOMPorts();
int portsSize=ports.length;
if (portsSize==0)
{
selectPort.getItems().add(LN.getString("settingsPage.noCOMPort"));
selectPort.setValue(LN.getString("settingsPage.noCOMPort"));
}
else if(portsSize==1)
{
selectPort.getItems().add(ports[0]);
selectPort.setValue(ports[0]);
}
else
{
for(int i=0;i<portsSize;i++)
{
selectPort.getItems().add(ports[i]);
}
selectPort.getItems().add(LN.getString("settingsPage.selectCOMPort"));
selectPort.setValue(LN.getString("settingsPage.selectCOMPort"));
}
}
示例4: getSelectModelEntries
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public static void getSelectModelEntries(ChoiceBox selectModel,String brandName)
{
selectModel.getItems().clear();
selectModel.getItems().add(LN.getString("general.selectModel"));
if(!brandName.equals(LN.getString("general.selectBrand"))&&!brandName.equals(LN.getString("general.notavailable")))
{
String[] models = sortArray(getAvailableEntries(ObdqProperties.workingDirectoryPath+ObdqProperties.carManufacturersPath+brandName+".csv" ));
int modelsSize=models.length;
for(int i=0;i<modelsSize;i++)
{
selectModel.getItems().add(models[i]);
}
selectModel.setDisable(false);
}
else
{
selectModel.setDisable(true);
}
selectModel.setValue(LN.getString("general.selectModel"));
}
示例5: testChangeLogLevelRunnable
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
/**
* This test will set the value of {@link LoggingSettingsViewController} {@link ChoiceBox} to value to different
* from the current {@link Level}.
* <p>
* The {@link LoggingSettingsViewController#onLogLevelChanged(ActionEvent)} method
* will be called which creates a new {@link Runnable} containing the command to update the {@link Level}.
* <p>
* The {@link Runnable} will be added to the {@link Settings} using {@link Settings#addRunnable(Runnable)}.
* {@link Settings} has been mocked and and a {@link ArgumentCaptor} has been added to intercept the runnable. After
* then runnable has been intercepted it can be invoked.
* <p>
* This test will then succeed if the log {@link Level} has been changed accordingly.
*/
@Test
void testChangeLogLevelRunnable() {
final ChoiceBox<String> choiceBox = new ChoiceBox<>();
String currentLevel = LogManager.getRootLogger().getLevel().toString();
final String newLevel;
if (currentLevel.equals("ERROR")) {
choiceBox.setValue("DEBUG");
newLevel = "DEBUG";
} else {
choiceBox.setValue("ERROR");
newLevel = "ERROR";
}
assertThat(currentLevel).isNotEqualTo(newLevel);
loggingSettingsViewController.setChoiceBox(choiceBox);
final ActionEvent event = new ActionEvent();
interact(() -> loggingSettingsViewController.onLogLevelChanged(event));
final ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
verify(settingsMock).addRunnable(captor.capture());
final Runnable command = captor.getValue();
command.run();
currentLevel = LogManager.getRootLogger().getLevel().toString();
assertThat(currentLevel).isEqualTo(newLevel);
}
示例6: 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();
}
示例7: createUndecoratedEditor
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
@Override
protected Node createUndecoratedEditor() {
final ChoiceBox<T> box = new ChoiceBox<>(alternatives);
final T val = currentValue.getValue();
if (alternatives.contains(val)) {
box.setValue(val);
} else {
box.setValue(alternatives.get(0));
}
currentValue.bindBidirectional(box.valueProperty());
return box;
}
示例8: 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;
}
}
示例9: getSelectCarEntries
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public static void getSelectCarEntries(ChoiceBox selectCar)
{
selectCar.getItems().clear();
try
{
int carSize=Globals.carsList.getSize();
if(carSize>0)
{
selectCar.getItems().add(LN.getString("historyPage.selectCar"));
for(int i=0;i<carSize;i++)
{
selectCar.getItems().add(Globals.carsList.getListEntry(i).getCarName());
}
if(Globals.selectedCar!=null)
{
selectCar.setValue(Globals.selectedCar.getCarName());
}
else
selectCar.setValue(LN.getString("historyPage.selectCar"));
}
else
{
selectCar.getItems().add(LN.getString("historyPage.noCarsAvailable"));
selectCar.setValue(LN.getString("historyPage.noCarsAvailable"));
}
}
catch(Exception e)
{
}
}
示例10: getSelectBaudRate
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public static void getSelectBaudRate(ChoiceBox selectBaudRate)
{
String[] baudRates = ObdqProperties.baudRates.split(",");
int ratesSize=baudRates.length;
if (ratesSize==0)
{
selectBaudRate.getItems().add(LN.getString("settingsPage.noBaudRate"));
selectBaudRate.setValue(LN.getString("settingsPage.noBaudRate"));
}
else if(ratesSize==1)
{
selectBaudRate.getItems().add(baudRates[0]);
selectBaudRate.setValue(baudRates[0]);
}
else
{
for(int i=0;i<ratesSize;i++)
{
selectBaudRate.getItems().add(baudRates[i]);
}
if(!ObdqProperties.defaultBaudRate.equals(""))
selectBaudRate.setValue(ObdqProperties.defaultBaudRate);
else
{
selectBaudRate.getItems().add(LN.getString("settingsPage.selectBaudRate"));
selectBaudRate.setValue(LN.getString("settingsPage.selectBaudRate"));
}
}
}
示例11: getSelectBrandEntries
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public static void getSelectBrandEntries(ChoiceBox selectBrand)
{
String[] brands = getAvailableCarManufacturers();
int brandsSize=brands.length;
selectBrand.getItems().add(LN.getString("general.selectBrand"));
for(int i=0;i<brandsSize;i++)
{
selectBrand.getItems().add(brands[i]);
}
selectBrand.setValue(LN.getString("general.selectBrand"));
}
示例12: getColorEntries
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public static void getColorEntries(ChoiceBox colorBox)
{
colorBox.getItems().add(LN.getString("general.selectColor"));
String[] colors = sortArray(getAvailableEntries(ObdqProperties.workingDirectoryPath+ObdqProperties.carColorsPath));
int colorsSize=colors.length;
for(int i=0;i<colorsSize;i++)
{
colorBox.getItems().add(LN.getString("general."+colors[i]));
}
colorBox.getItems().add(LN.getString("general.other"));
colorBox.setValue(LN.getString("general.selectColor"));
}
示例13: getBodyTypesEntries
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public static void getBodyTypesEntries(ChoiceBox bodyTypeBox)
{
bodyTypeBox.getItems().add(LN.getString("general.selectBodyType"));
String[] bodyTypes = sortArray(getAvailableEntries(ObdqProperties.workingDirectoryPath+ObdqProperties.carBodyTypesPath));
int bodyTypesSize=bodyTypes.length;
for(int i=0;i<bodyTypesSize;i++)
{
bodyTypeBox.getItems().add(LN.getString("general."+bodyTypes[i]));
}
bodyTypeBox.getItems().add(LN.getString("general.other"));
bodyTypeBox.setValue(LN.getString("general.selectBodyType"));
}
示例14: getFuelTypesEntries
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public static void getFuelTypesEntries(ChoiceBox fuelTypeBox)
{
fuelTypeBox.getItems().add(LN.getString("general.selectFuelType"));
String[] bodyTypes = sortArray(getAvailableEntries(ObdqProperties.workingDirectoryPath+ObdqProperties.carFuelTypesPath));
int bodyTypesSize=bodyTypes.length;
for(int i=0;i<bodyTypesSize;i++)
{
fuelTypeBox.getItems().add(LN.getString("general."+bodyTypes[i]));
}
fuelTypeBox.getItems().add(LN.getString("general.other"));
fuelTypeBox.setValue(LN.getString("general.selectFuelType"));
}
示例15: getYearEntries
import javafx.scene.control.ChoiceBox; //导入方法依赖的package包/类
public static void getYearEntries(ChoiceBox yearBox)
{
yearBox.getItems().add(LN.getString("general.selectYear"));
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
for(int i=year;i>=1940;i--)
{
yearBox.getItems().add(String.valueOf(i));
}
yearBox.setValue(LN.getString("general.selectYear"));
}