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