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


Java ChoiceBox.setValue方法代码示例

本文整理汇总了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);
    
   
   
    
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:41,代码来源:ChoiceBoxSample.java

示例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);

   }
 
开发者ID:dice-group,项目名称:LIMES,代码行数:24,代码来源:MachineLearningView.java

示例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"));
    }

}
 
开发者ID:obdq,项目名称:obdq,代码行数:26,代码来源:SettingPageController.java

示例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"));

}
 
开发者ID:obdq,项目名称:obdq,代码行数:22,代码来源:CarAddPageController.java

示例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);
}
 
开发者ID:ProgrammingLife2017,项目名称:hygene,代码行数:44,代码来源:LoggingSettingsViewControllerTest.java

示例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();
}
 
开发者ID:bekwam,项目名称:examples-javafx-repos1,代码行数:38,代码来源:ChoiceBoxDemo.java

示例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;
}
 
开发者ID:speedment,项目名称:speedment,代码行数:15,代码来源:ChoiceBoxItem.java

示例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;
    }
}
 
开发者ID:badvision,项目名称:jace,代码行数:32,代码来源:ConfigurationUIController.java

示例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)
     {
     }
}
 
开发者ID:obdq,项目名称:obdq,代码行数:33,代码来源:HistoryPageController.java

示例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"));
        }
    }

}
 
开发者ID:obdq,项目名称:obdq,代码行数:31,代码来源:SettingPageController.java

示例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"));

}
 
开发者ID:obdq,项目名称:obdq,代码行数:13,代码来源:CarAddPageController.java

示例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"));
}
 
开发者ID:obdq,项目名称:obdq,代码行数:14,代码来源:CarAddPageController.java

示例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"));
}
 
开发者ID:obdq,项目名称:obdq,代码行数:14,代码来源:CarAddPageController.java

示例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"));
}
 
开发者ID:obdq,项目名称:obdq,代码行数:14,代码来源:CarAddPageController.java

示例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"));
}
 
开发者ID:obdq,项目名称:obdq,代码行数:13,代码来源:CarAddPageController.java


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