本文整理匯總了Java中javafx.scene.control.Toggle類的典型用法代碼示例。如果您正苦於以下問題:Java Toggle類的具體用法?Java Toggle怎麽用?Java Toggle使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Toggle類屬於javafx.scene.control包,在下文中一共展示了Toggle類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: TypedToggleGroup
import javafx.scene.control.Toggle; //導入依賴的package包/類
public TypedToggleGroup() {
this.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
@Override
@SuppressWarnings("unchecked")
public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
if (newValue != null) {
T obj = (T) newValue.getUserData();
selectedValueProperty.setValue(obj);
} else {
selectedValueProperty.setValue(null);
}
}
});
}
示例2: getSecretValue
import javafx.scene.control.Toggle; //導入依賴的package包/類
private SecretValue getSecretValue(ToggleGroup valueSource, String value, String generated, File file) {
Toggle current = valueSource.getSelectedToggle();
String secretString;
if (current.getUserData().equals("value")) {
secretString = value;
} else if (current.getUserData().equals("generated")) {
Integer numBytesToGenerate = Integer.valueOf(generated);
// TODO: store as plain bytes?
byte[] random = Singleton.randomGenerator.generateRandom(numBytesToGenerate);
secretString = Base64.encodeAsString(random);
} else {
String path = null;
try {
path = file.getCanonicalPath();
return SecretValueConverter.inferEncoding(Files.readAllBytes(Paths.get(path)), SecretType.OPAQUE);
} catch (IOException e) {
throw new RuntimeException("Failed to read secret from file");
}
}
return new SecretValue(secretString, SecretType.OPAQUE);
}
示例3: initialize
import javafx.scene.control.Toggle; //導入依賴的package包/類
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
final Image tempImage = new Image(getClass().getResourceAsStream("/images/Valencia.jpg"));
tempimg.setImage(tempImage);
temprb.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
if (temprb.getSelectedToggle() != null) {
RadioButton chk = (RadioButton) old_toggle.getToggleGroup().getSelectedToggle();
System.out.println("Selected Radio Button - " + chk.getText());
final Image image = new Image(
getClass().getResourceAsStream("/images/" + chk.getText().toString() + ".jpg"
// Cast object to radio button
// System.out.println("Selected Radio Button -
// "+chk.getText());
));
tempimg.setImage(image);
}
}
});
}
示例4: TemplateField
import javafx.scene.control.Toggle; //導入依賴的package包/類
public TemplateField(String name, String label, boolean isSelected, String constant) {
this.name = name;
this.label = label;
this.isSelected = isSelected;
this.selection = "YES";
this.value = constant;
labelElement = new WikiLabel(label).setWidth(200, 500).setHeight(35);
buttonYes.setSelected(true);
group.selectedToggleProperty().addListener((ObservableValue<? extends Toggle> ov, Toggle tOld, Toggle tNew) -> {
RadioButton btn = (RadioButton) tNew.getToggleGroup().getSelectedToggle();
setSelection(btn.getId());
});
valueText.setOnKeyReleased((KeyEvent event) -> {
this.value = valueText.getText();
});
}
示例5: changed
import javafx.scene.control.Toggle; //導入依賴的package包/類
@Override
public void changed(ObservableValue<? extends Toggle> pObservableValue, Toggle pOld, Toggle pNew)
{
if( aScene != null )
{
aScene.getStylesheets().clear();
switch(aSkin.getSelectedToggle().getUserData().toString())
{
case "Floral":
aScene.getStylesheets().add(Welcome.class.getResource("cs1.css").toExternalForm());
break;
case "Chintz":
aScene.getStylesheets().add(Welcome.class.getResource("cs2.css").toExternalForm());
break;
default:
break;
}
}
}
示例6: removeButton
import javafx.scene.control.Toggle; //導入依賴的package包/類
public void removeButton(T ref) {
if (!items.containsKey(ref)) {
logger.error("removeButton on non-existing ref - {}", ref);
return;
}
final Node item = items.remove(ref);
if (Platform.isFxApplicationThread()) {
subContainer.getChildren().remove(item);
} else {
Platform.runLater(() -> subContainer.getChildren().remove(item));
}
if (toggleable && ref == defaultSelection) {
defaultSelection = null;
}
if (toggleable && ref == currentSelection && defaultSelection != null) {
currentSelection = defaultSelection;
itemListener.onItemClicked(currentSelection);
toggleGroup.selectToggle((Toggle) items.get(currentSelection));
}
}
示例7: getOpenDisplayAction
import javafx.scene.control.Toggle; //導入依賴的package包/類
/** @return {@link OpenDisplayActionInfo} from sub pane */
private OpenDisplayActionInfo getOpenDisplayAction()
{
Target target = Target.REPLACE;
List<Toggle> modes = open_display_targets.getToggles();
for (int i=0; i<modes.size(); ++i)
if (modes.get(i).isSelected())
{
target = Target.values()[i];
break;
}
return new OpenDisplayActionInfo(open_display_description.getText(),
open_display_path.getText().trim(),
open_display_macros.getMacros(),
target);
}
示例8: initialize
import javafx.scene.control.Toggle; //導入依賴的package包/類
@Override
public void initialize(URL location, ResourceBundle resources) {
closeJarButton.setDisable(Main.getLoadedJar() == null);
loadMappingsButton.setDisable(Main.getLoadedJar() == null);
mergeMappingsButton.setDisable(Main.getLoadedJar() == null);
saveMappingsButton.setDisable(Main.getLoadedJar() == null);
saveMappingsAsButton.setDisable(Main.getLoadedJar() == null);
resetMappingsButton.setDisable(Main.getLoadedJar() == null);
final String langRadioPrefix = "langRadio-";
for (Toggle toggle : languageGroup.getToggles()) {
if (((RadioMenuItem) toggle).getId().equals(langRadioPrefix + Main.getCurrentLocale())) {
toggle.setSelected(true);
break;
}
}
setAccelerators();
this.initTreeViews();
RESTART_ALERT.setTitle(Main.getResourceBundle().getString("dialog.restart.title"));
RESTART_ALERT.setHeaderText(null);
RESTART_ALERT.setContentText(Main.getResourceBundle().getString("dialog.restart.content"));
}
示例9: setValidationSupport
import javafx.scene.control.Toggle; //導入依賴的package包/類
@Override
public void setValidationSupport(ValidationSupport validationSupport) {
this.validationSupport = validationSupport;
Validator<Toggle> operationValidator = (c, newValue) -> {
String whyBad = null;
if (newValue != null) {
String nameOfOperator = ((ToggleButton) newValue).getText();
BooleanOperator operator = BooleanOperator.valueOf(nameOfOperator);
if (logicalChecker != null) {
// Internally the result will depend on amount of children.
whyBad = logicalChecker
.whyOperatorCantBeAppliedToCurrentAmountOfCheckers(operator);
}
}
ValidationResult wrongResult = ValidationResult.fromErrorIf(c,
whyBad, whyBad != null);
if (newValue != null) {
ToggleButton origTB = mapWithButtons.get(origLogicalChecker.getOperator().name());
buttonStateManager.reportNewValueOfControl(origTB, newValue, c, wrongResult);
}
return wrongResult;
};
this.validationSupport.registerValidator(segmentedButton, operationValidator);
}
示例10: initialize
import javafx.scene.control.Toggle; //導入依賴的package包/類
public void initialize() {
//init values
mExpanded = new SimpleBooleanProperty(true);
mSelectedButton = new SimpleObjectProperty<>(SideButton.NONE);
//minimize the side pane
handleMenuButtonAction();
//add toggle listener
sideButton.selectedToggleProperty().addListener(
(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) -> {
if (newValue != null) {
selectedButtonChanged((ToggleButton) newValue);
} else {
oldValue.setSelected(true);
}
});
}
示例11: ToggleButtonSample
import javafx.scene.control.Toggle; //導入依賴的package包/類
public ToggleButtonSample() {
// create label to show result of selected toggle button
final Label label = new Label();
label.setStyle("-fx-font-size: 2em;");
// create 3 toggle buttons and a toogle group for them
final ToggleButton tb1 = new ToggleButton("Cat");
final ToggleButton tb2 = new ToggleButton("Dog");
final ToggleButton tb3 = new ToggleButton("Horse");
ToggleGroup group = new ToggleGroup();
tb1.setToggleGroup(group);
tb2.setToggleGroup(group);
tb3.setToggleGroup(group);
group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
@Override public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle selectedToggle) {
if(selectedToggle!=null) {
label.setText(((ToggleButton) selectedToggle).getText());
}
else {
label.setText("...");
}
}
});
// select the first button to start with
group.selectToggle(tb1);
// add buttons and label to grid and set their positions
GridPane.setConstraints(tb1,0,0);
GridPane.setConstraints(tb2,1,0);
GridPane.setConstraints(tb3,2,0);
GridPane.setConstraints(label,0,1,3,1);
GridPane grid = new GridPane();
grid.setVgap(20);
grid.setHgap(10);
getChildren().add(grid);
grid.getChildren().addAll(tb1, tb2, tb3, label);
}
示例12: start
import javafx.scene.control.Toggle; //導入依賴的package包/類
@Override
public void start(Stage stage) {
stage.setTitle("Toggle Button Sample");
stage.setWidth(250);
stage.setHeight(180);
HBox hbox = new HBox();
VBox vbox = new VBox();
Scene scene = new Scene(new Group(vbox));
stage.setScene(scene);
scene.getStylesheets().add("togglebuttonsample/ControlStyle.css");
Rectangle rect = new Rectangle();
rect.setHeight(50);
rect.setFill(Color.WHITE);
rect.setStroke(Color.DARKGRAY);
rect.setStrokeWidth(2);
rect.setArcHeight(10);
rect.setArcWidth(10);
final ToggleGroup group = new ToggleGroup();
group.selectedToggleProperty().addListener(
(ObservableValue<? extends Toggle> ov,
Toggle toggle, Toggle new_toggle) -> {
if (new_toggle == null)
rect.setFill(Color.WHITE);
else
rect.setFill((Color) group.getSelectedToggle().getUserData());
});
ToggleButton tb1 = new ToggleButton("Minor");
tb1.setToggleGroup(group);
tb1.setUserData(Color.LIGHTGREEN);
tb1.setSelected(true);
tb1.getStyleClass().add("toggle-button1");
ToggleButton tb2 = new ToggleButton("Major");
tb2.setToggleGroup(group);
tb2.setUserData(Color.LIGHTBLUE);
tb2.getStyleClass().add("toggle-button2");
ToggleButton tb3 = new ToggleButton("Critical");
tb3.setToggleGroup(group);
tb3.setUserData(Color.SALMON);
tb3.getStyleClass().add("toggle-button3");
hbox.getChildren().addAll(tb1, tb2, tb3);
vbox.getChildren().add(new Label("Priority:"));
vbox.getChildren().add(hbox);
vbox.getChildren().add(rect);
vbox.setPadding(new Insets(20, 10, 10, 20));
stage.show();
rect.setWidth(hbox.getWidth());
}
示例13: addToggleGroup
import javafx.scene.control.Toggle; //導入依賴的package包/類
/**
* Add an enumeration of options to a wizard step. Multiple RadioButtons
* will be used (horizontally-aligned).
*
* @param fieldName
* @param options
* list of choices.
* @param prompt
* the text to show on the buttons tooltip.
* @param defaultValue
* the default value to be selected.
* @return
*/
@SuppressWarnings("unchecked")
public WizardStepBuilder addToggleGroup(final String fieldName, final String[] options, final String[] prompt,
final int defaultValue)
{
final ToggleGroup group = new ToggleGroup();
final HBox box = new HBox();
for (int i = 0; i < options.length; i++)
{
final JFXRadioButton radio = new JFXRadioButton(options[i]);
radio.setPadding(new Insets(10));
radio.setToggleGroup(group);
radio.setTooltip(new Tooltip(prompt[i]));
radio.setUserData(options[i]);
if (i == defaultValue)
radio.setSelected(true);
box.getChildren().add(radio);
}
this.current.getData().put(fieldName, new ReadOnlyObjectWrapper<Toggle>());
this.current.getData().get(fieldName).bind(group.selectedToggleProperty());
final Label label = new Label(fieldName);
GridPane.setHalignment(label, HPos.RIGHT);
GridPane.setHalignment(box, HPos.LEFT);
this.current.add(label, 0, this.current.getData().size() - 1);
this.current.add(box, 1, this.current.getData().size() - 1);
return this;
}
示例14: getPlacementToggle
import javafx.scene.control.Toggle; //導入依賴的package包/類
public boolean getPlacementToggle() {
Toggle in = placementToggleGroup.getSelectedToggle();
boolean out = false;
if(in == activePlace) out = true;
return out;
}
示例15: initialize
import javafx.scene.control.Toggle; //導入依賴的package包/類
@FXML
void initialize() {
if (Language.RO.equals(langCtr.getLanguage())) {
engRadio.setSelected(false);
romRadio.setSelected(true);
}
langGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue, Toggle newValue) {
changeLanguage();
}
});
}