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


Java ChoiceBox类代码示例

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


ChoiceBox类属于javafx.scene.control包,在下文中一共展示了ChoiceBox类的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: setFormConstraints

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
private void setFormConstraints(Node field) {
    if (field instanceof ISetConstraints) {
        ((ISetConstraints) field).setFormConstraints(this);
    } else if (field instanceof Button) {
        _setFormConstraints((Button) field);
    } else if (field instanceof TextField) {
        _setFormConstraints((TextField) field);
    } else if (field instanceof TextArea) {
        _setFormConstraints((TextArea) field);
    } else if (field instanceof ComboBox<?>) {
        _setFormConstraints((ComboBox<?>) field);
    } else if (field instanceof ChoiceBox<?>) {
        _setFormConstraints((ChoiceBox<?>) field);
    } else if (field instanceof CheckBox) {
        _setFormConstraints((CheckBox) field);
    } else if (field instanceof Spinner<?>) {
        _setFormConstraints((Spinner<?>) field);
    } else if (field instanceof VBox) {
        _setFormConstraints((VBox) field);
    } else if (field instanceof Label) {
        _setFormConstraints((Label) field);
    } else {
        LOGGER.info("FormPane.setFormConstraints(): unknown field type: " + field.getClass().getName());
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:26,代码来源:FormPane.java

示例3: htmlOptionSelect

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
@Test public void htmlOptionSelect() {
    @SuppressWarnings("unchecked")
    ChoiceBox<String> choiceBox = (ChoiceBox<String>) getPrimaryStage().getScene().getRoot().lookup(".choice-box");
    LoggingRecorder lr = new LoggingRecorder();
    String text = "This is a test text";
    final String htmlText = "<html><font color=\"RED\"><h1><This is also content>" + text + "</h1></html>";
    Platform.runLater(() -> {
        RFXChoiceBox rfxChoiceBox = new RFXChoiceBox(choiceBox, null, null, lr);
        choiceBox.getItems().add(htmlText);
        choiceBox.getSelectionModel().select(htmlText);
        rfxChoiceBox.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals(text, recording.getParameters()[0]);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:18,代码来源:RFXChoiceBoxTest.java

示例4: getText

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
@Test public void getText() {
    ChoiceBox<?> choiceBox = (ChoiceBox<?>) getPrimaryStage().getScene().getRoot().lookup(".choice-box");
    LoggingRecorder lr = new LoggingRecorder();
    List<String> text = new ArrayList<>();
    Platform.runLater(() -> {
        RFXChoiceBox rfxChoiceBox = new RFXChoiceBox(choiceBox, null, null, lr);
        choiceBox.getSelectionModel().select(1);
        rfxChoiceBox.focusLost(null);
        text.add(rfxChoiceBox._getText());
    });
    new Wait("Waiting for choice box text.") {
        @Override public boolean until() {
            return text.size() > 0;
        }
    };
    AssertJUnit.assertEquals("Cat", text.get(0));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:18,代码来源:RFXChoiceBoxTest.java

示例5: buildEyeTrackerConfigChooser

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
private static ChoiceBox<EyeTracker> buildEyeTrackerConfigChooser(Configuration configuration,
        ConfigurationContext configurationContext) {
    ChoiceBox<EyeTracker> choiceBox = new ChoiceBox<>();

    choiceBox.getItems().addAll(EyeTracker.values());

    EyeTracker selectedEyeTracker = findSelectedEyeTracker(configuration);
    choiceBox.getSelectionModel().select(selectedEyeTracker);

    choiceBox.setPrefWidth(prefWidth);
    choiceBox.setPrefHeight(prefHeight);

    choiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<EyeTracker>() {
        @Override
        public void changed(ObservableValue<? extends EyeTracker> observable, EyeTracker oldValue,
                EyeTracker newValue) {
            final String newPropertyValue = newValue.name();
            ConfigurationBuilder.createFromPropertiesResource().withEyeTracker(newPropertyValue)
                    .saveConfigIgnoringExceptions();
        }
    });

    return choiceBox;
}
 
开发者ID:schwabdidier,项目名称:GazePlay,代码行数:25,代码来源:ConfigurationContext.java

示例6: updateItem

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
static <T> void updateItem(final Cell<T> cell,
        final StringConverter<T> converter,
        final HBox hbox,
        final Node graphic,
        final ChoiceBox<T> choiceBox
) {
    if (cell.isEmpty()) {
        cell.setText(null);
        cell.setGraphic(null);
    } else if (cell.isEditing()) {
        if (choiceBox != null) {
            choiceBox.getSelectionModel().select(cell.getItem());
        }
        cell.setText(null);

        if (graphic != null) {
            hbox.getChildren().setAll(graphic, choiceBox);
            cell.setGraphic(hbox);
        } else {
            cell.setGraphic(choiceBox);
        }
    } else {
        cell.setText(getItemText(cell, converter));
        cell.setGraphic(graphic);
    }
}
 
开发者ID:Naoghuman,项目名称:ABC-List,代码行数:27,代码来源:CellUtils.java

示例7: CommonsChoiceBoxTableCell

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
public CommonsChoiceBoxTableCell(ObservableList<CodeDVO> codes, StringConverter<CodeDVO> stringConverter) {
	this.codes = codes;
	this.stringConverter = stringConverter;
	choiceBox = new ChoiceBox<>(codes);
	choiceBox.setConverter(stringConverter);
	choiceBox.setOnAction(event -> {

		CodeDVO value = choiceBox.getValue();
		if (value == null)
			return;

		ObservableValue<String> cellObservableValue = getTableColumn().getCellObservableValue(getIndex());
		WritableStringValue writableStringValue = (WritableStringValue) cellObservableValue;
		if (cellObservableValue instanceof WritableStringValue) {
			writableStringValue.set(value.getCode());
		}
		event.consume();
	});

}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:21,代码来源:CommonsChoiceBoxTableCell.java

示例8: macroDropdownSetup

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
/**
 * Initialises the macro dropdown.
 * @return
 * 		A choicebox representing the macro dropdown.
 */
private ChoiceBox<String> macroDropdownSetup() {
    ChoiceBox<String> macroDropdown = new ChoiceBox<String>();
    macroDropdown.getSelectionModel().selectedIndexProperty()
            .addListener(new ChangeListener<Number>() {
                public void changed(
                        ObservableValue<? extends Number> observable,
                        Number value, Number newValue) {
                    if ((int) newValue >= 0) {
                        taskViewerController.runTaskMacro(macroDropdown
                                .getItems().get((int) newValue));
                        macroDropdown.getSelectionModel().select(-1);
                    }
                }
            });
    return macroDropdown;
}
 
开发者ID:UQdeco2800,项目名称:farmsim,代码行数:22,代码来源:TaskViewer.java

示例9: agentSelectorSetup

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
private ChoiceBox<String> agentSelectorSetup() {
    workerList = new ArrayList<Agent>();
    ChoiceBox<String> dropdown = new ChoiceBox<String>(
            controller.getAgentList(tasks.get(0), workerList));
    dropdown.getSelectionModel().selectedIndexProperty()
            .addListener(new ChangeListener<Number>() {
                public void changed(
                        ObservableValue<? extends Number> observable,
                        Number value, Number newValue) {
                    if ((int) newValue >= 0) {
                        controller.setWorkerForTasks(tasks,
                                workerList.get((int) newValue));
                    }
                }
            });
    return dropdown;
}
 
开发者ID:UQdeco2800,项目名称:farmsim,代码行数:18,代码来源:TaskPane.java

示例10: testUpScalingQuality

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
@Ignore
public void testUpScalingQuality() throws Exception {
    for (EScalingAlgorithm algo : EScalingAlgorithm.getAllEnabled()) {
        if (algo.getSupportedForType().contains(EScalingAlgorithm.Type.UPSCALING)) {

            ChoiceBox choiceBox = (ChoiceBox) scene.lookup("#choiceUpScale");
            //choiceBox.getSelectionModel().
            for (Object o : choiceBox.getItems()) {
                if (o.toString().equals(algo.toString())) {

                }
            }
            clickOn("#choiceUpScale").clickOn(algo.toString());
            assertEquals("arguments should match", defaultBuilder.upScaleAlgorithm(algo).build(), controller.getFromUI(false));
        }
    }
}
 
开发者ID:patrickfav,项目名称:density-converter,代码行数:18,代码来源:GUITest.java

示例11: ObjectPropertyValueSetter

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
public ObjectPropertyValueSetter(Property listeningProperty, BindingType btype, Object testedControl, List values) {
    try {
        ChoiceBox cb = new ChoiceBox();
        cb.setMaxWidth(175.0);
        cb.setId(createId(listeningProperty, btype));
        cb.setItems(FXCollections.observableArrayList(values));
        cb.getSelectionModel().selectFirst();

        leadingControl = cb;
        this.leadingProperty = cb.valueProperty();
        this.listeningProperty = listeningProperty;
        propertyValueType = PropertyValueType.OBJECTENUM;
        initialValue1 = !values.isEmpty() ? values.get(0) : null;

        bindComponent(btype, testedControl);
    } catch (Throwable ex) {
        log(ex);
    }
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:20,代码来源:ObjectPropertyValueSetter.java

示例12: NodesChoserFactory

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
/**
 * For all controls except menu.
 *
 * @param actionName title on button.
 * @param handler action, which will be called, when button will be clicked
 * and selected node will be given as argument.
 * @param additionalNodes nodes between ChoiceBox with different controls
 * and action button. You can add and process them, when action happens.
 */
public NodesChoserFactory(String actionName, final NodeAction<Node> handler, Node additionalNodes) {
    final ChoiceBox<NodeFactory> cb = new ChoiceBox<NodeFactory>();
    cb.setId(NODE_CHOSER_CHOICE_BOX_ID);
    cb.getItems().addAll(ControlsFactory.filteredValues());
    cb.getItems().addAll(Shapes.values());
    cb.getItems().addAll(Panes.values());

    Button actionButton = new Button(actionName);
    actionButton.setId(NODE_CHOOSER_ACTION_BUTTON_ID);
    actionButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
            handler.execute(cb.getSelectionModel().getSelectedItem().createNode());
        }
    });

    this.getChildren().add(cb);
    this.getChildren().add(additionalNodes);
    this.getChildren().add(actionButton);
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:29,代码来源:NodesChoserFactory.java

示例13: setUpVars

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
public static void setUpVars() throws Exception {
    scene = Root.ROOT.lookup().wrap();
    sceneAsParent = scene.as(Parent.class, Node.class);
    object = container = (MenuButtonWrap) sceneAsParent.lookup(new LookupCriteria<Node>() {
        public boolean check(Node cntrl) {
            return MenuButton.class.isAssignableFrom(cntrl.getClass());
        }
    }).wrap();
    contentPane = sceneAsParent.lookup(new ByID<Node>(MenuButtonApp.TEST_PANE_ID)).wrap();
    clearBtn = sceneAsParent.lookup(new ByText(MenuButtonApp.CLEAR_BTN_ID)).wrap();
    resetBtn = sceneAsParent.lookup(new ByText(MenuButtonApp.RESET_BTN_ID)).wrap();
    addPosBtn = sceneAsParent.lookup(new ByText(MenuButtonApp.ADD_SINGLE_AT_POS_BTN_ID)).wrap();
    removePosBtn = sceneAsParent.lookup(new ByText(MenuButtonApp.REMOVE_SINGLE_AT_POS_BTN_ID)).wrap();
    check = (Wrap<? extends Label>) sceneAsParent.lookup(new ByID(MenuButtonApp.LAST_SELECTED_ID)).wrap();
    sideCB = sceneAsParent.lookup(ChoiceBox.class).wrap();
    menuButtonAsStringMenuOwner = container.as(StringMenuOwner.class, Menu.class);
    menuButtonAsParent = container.as(Parent.class, MenuItem.class);
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:19,代码来源:MenuButtonTest.java

示例14: FontPane

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
public FontPane() {
    super();
    setSpacing(5);
    fNames = new ChoiceBox();
    fNames.getItems().addAll(Font.getFontNames());
    fFamily = new Label();
    fSize = new TextField();
    fStyle = new Label();
    HBox fNamesBox = new HBox();
    fNamesBox.getChildren().addAll(new Label("Name:"), fNames);
    HBox fFamiliesBox = new HBox();
    fFamiliesBox.getChildren().addAll(new Label("Family:"), fFamily);
    HBox fSizeBox = new HBox();
    fSizeBox.getChildren().addAll(new Label("Size:"), fSize);
    HBox fStyleBox = new HBox();
    fStyleBox.getChildren().addAll(new Label("Style:"), fStyle);
    getChildren().addAll(fNamesBox, fFamiliesBox, fSizeBox, fStyleBox);
}
 
开发者ID:teamfx,项目名称:openjfx-8u-dev-tests,代码行数:19,代码来源:RichTextPropertiesApp.java

示例15: JrdsAdapterDialog

import javafx.scene.control.ChoiceBox; //导入依赖的package包/类
/**
 * Initializes a new instance of the {@link JrdsAdapterDialog} class.
 *
 * @param owner the owner window for the dialog
 */
public JrdsAdapterDialog(Node owner) {
    super(owner, Mode.URL);
    this.parent.setHeaderText("Connect to a JRDS source");
    this.tabsChoiceBox = new ChoiceBox<>();
    tabsChoiceBox.getItems().addAll(JrdsTreeViewTab.values());
    this.extraArgumentTextField = new TextField();
    HBox.setHgrow(extraArgumentTextField, Priority.ALWAYS);
    HBox hBox = new HBox(tabsChoiceBox, extraArgumentTextField);
    hBox.setSpacing(10);
    GridPane.setConstraints(hBox, 1, 2, 1, 1, HPos.LEFT, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS, new Insets(4, 0, 4, 0));
    tabsChoiceBox.getSelectionModel().select(JrdsTreeViewTab.HOSTS_TAB);
    Label tabsLabel = new Label("Sorted By:");
    GridPane.setConstraints(tabsLabel, 0, 2, 1, 1, HPos.LEFT, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS, new Insets(4, 0, 4, 0));
    this.paramsGridPane.getChildren().addAll(tabsLabel, hBox);
    extraArgumentTextField.visibleProperty().bind(Bindings.createBooleanBinding(() -> this.tabsChoiceBox.valueProperty().get().getArgument() != null, this.tabsChoiceBox.valueProperty()));
}
 
开发者ID:fthevenet,项目名称:binjr,代码行数:22,代码来源:JrdsAdapterDialog.java


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