本文整理汇总了Java中javafx.scene.control.ToggleGroup类的典型用法代码示例。如果您正苦于以下问题:Java ToggleGroup类的具体用法?Java ToggleGroup怎么用?Java ToggleGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ToggleGroup类属于javafx.scene.control包,在下文中一共展示了ToggleGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRadioButton
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
private RadioButton createRadioButton(final Node rect, String name, final boolean toFront, ToggleGroup tg) {
final RadioButton radioButton = new RadioButton(name);
radioButton.setToggleGroup(tg);
radioButton.selectedProperty().addListener(new InvalidationListener() {
public void invalidated(Observable ov) {
if (radioButton.isSelected()) {
if (toFront) {
rect.toFront();
} else {
rect.toBack();
}
}
}
});
return radioButton;
}
示例2: RadioButtons
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
public RadioButtons() {
super(400,100);
ToggleGroup tg = new ToggleGroup();
VBox vbox = new VBox();
vbox.setSpacing(5);
RadioButton rb1 = new RadioButton("Hello");
rb1.setToggleGroup(tg);
RadioButton rb2 = new RadioButton("Bye");
rb2.setToggleGroup(tg);
rb2.setSelected(true);
RadioButton rb3 = new RadioButton("Disabled");
rb3.setToggleGroup(tg);
rb3.setSelected(false);
rb3.setDisable(true);
vbox.getChildren().add(rb1);
vbox.getChildren().add(rb2);
vbox.getChildren().add(rb3);
getChildren().add(vbox);
}
示例3: createButtonGroup
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
/**
* Create a radio button for each String in the list, add them to the container, and bind the selected value to the
* String property
*
* @param container Container to put radio buttons in
* @param radioBtns List of Strings, one for each radio button
* @param modelProperty Property to bind selected radio button's value to
*/
public static ToggleGroupValue createButtonGroup(Pane container, List<String> radioBtns, StringProperty modelProperty) {
// Create new ToggleGroup and ToggleGroupValue for the radio buttons
ToggleGroupValue groupValue = new ToggleGroupValue();
ToggleGroup btnsGroup = new ToggleGroup();
// Create a radio button for each option
for (String s : radioBtns) {
// Create radio button for this option
RadioButton radioBtn = new RadioButton(s);
radioBtn.setUserData(s);
radioBtn.setToggleGroup(btnsGroup);
// Add to RadioButton to the container pane and the ToggleGroupValue
container.getChildren().add(radioBtn);
groupValue.add(radioBtn, radioBtn.getUserData());
}
// Bind toggle group value to model
modelProperty.bindBidirectional(groupValue.valueProperty());
// Select first option
groupValue.setValue(radioBtns.get(0));
return groupValue;
}
示例4: bind
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
public void bind(final ToggleGroup toggleGroup, final String propertyName) {
try {
String value = props.getProperty(propertyName);
if (value != null) {
int selectedToggleIndex = Integer.parseInt(value);
toggleGroup.selectToggle(toggleGroup.getToggles().get(selectedToggleIndex));
}
} catch (Exception ignored) {
}
toggleGroup.selectedToggleProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable o) {
if (toggleGroup.getSelectedToggle() == null) {
props.remove(propertyName);
} else {
props.setProperty(propertyName, Integer.toString(toggleGroup.getToggles().indexOf(toggleGroup.getSelectedToggle())));
}
}
});
}
示例5: updateMenuItems
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
private void updateMenuItems() {
ToggleGroup group = new ToggleGroup();
List<MenuItem> items = new ArrayList<>();
for (Calendar calendar : getSkinnable().getCalendars()) {
RadioMenuItem item = new RadioMenuItem(calendar.getName());
Rectangle icon = new Rectangle(10, 10);
icon.setArcHeight(2);
icon.setArcWidth(2);
icon.getStyleClass().add(calendar.getStyle() + "-icon"); //$NON-NLS-1$
item.setGraphic(icon);
item.setDisable(calendar.isReadOnly());
item.setOnAction(evt -> getSkinnable().setCalendar(calendar));
group.getToggles().add(item);
items.add(item);
if (calendar.equals(getSkinnable().getCalendar())) {
item.setSelected(true);
}
}
button.getItems().setAll(items);
}
示例6: getSecretValue
import javafx.scene.control.ToggleGroup; //导入依赖的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);
}
示例7: initMenu
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
private void initMenu() {
recentSupport = new RecentFileMenuSupport(openRecentMenu) {
@Override
public List<String> load() {
return Arrays.asList(Config.getProperty(ConfigKey.RECENT_LOCATIONS, "").split(","));
}
@Override
public void save(List<String> s) {
Config.setProperty(ConfigKey.RECENT_LOCATIONS, String.join(", ", s));
}
};
recentSupport.setOnAction(this::openFile);
ToggleGroup group = new ToggleGroup();
for (SkinStyle style : Context.SKIN.getSkinList()) {
RadioMenuItem item = new RadioMenuItem(style.getName());
item.setToggleGroup(group);
item.setOnAction(e -> Context.SKIN.changeSkin(style));
if (Context.SKIN.currentSkin() == style) {
item.setSelected(true);
}
skinMenu.getItems().add(item);
}
}
示例8: initItems
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
/**
* 初始化选择项
*/
private void initItems(){
// 左边的选择项
ObservableList<Node> items = boxItems.getChildren();
ToggleGroup group = new ToggleGroup();
// 关联group和index
for(int index=0; index<items.size(); ++index){
ToggleButton item = (ToggleButton) items.get(index);
item.setToggleGroup(group);
item.setUserData(index);
}
// 切换监听
group.selectedToggleProperty().addListener((observable, oldValue, newValue) ->{
if(newValue != null){
Integer itemIndex = (Integer) newValue.getUserData();
showSettingContent(itemIndex);
}else{
group.selectToggle(oldValue);
}
});
// 默认选择第一个
group.getToggles().get(0).setSelected(true);
}
示例9: makeDataSelector
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
/**
* Data selector between VoogaBoolean and VoogaNumber.
* @return
*/
private HBox makeDataSelector () {
ToggleGroup group = new ToggleGroup();
RadioButton number = new RadioButton("Number");
number.setToggleGroup(group);
number.setSelected(true);
RadioButton bool = new RadioButton("Boolean");
bool.setToggleGroup(group);
number.selectedProperty().addListener( (obs, old, newVal) -> {
container.getChildren().remove(buttons);
if (newVal) {
container.getChildren().add(numberSelector);
container.getChildren().remove(boolSelector);
chosenData = VOOGA_NUMBER;
}
else {
container.getChildren().remove(numberSelector);
container.getChildren().add(boolSelector);
chosenData = VOOGA_BOOLEAN;
}
container.getChildren().add(buttons);
});
return GUIUtils.makeRow(number, bool);
}
示例10: SessionConflictDialog
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
public SessionConflictDialog( Session scheduled, Session proposed, SessionVisuals sessionVisuals ){
this.rootNode.getStyleClass().add("session-conflict-dialog");
this.sessionVisuals = sessionVisuals;
setTitle(new Label(OTNBundle.getString("OTN.CONFLICT.SCHEDULE_CONFLICT")));
RadioButton rbScheduled = new RadioButton(OTNBundle.getString("OTN.CONFLICT.CURRENTLY_SCHEDULED"));
RadioButton rbProposed = new RadioButton(OTNBundle.getString("OTN.CONFLICT.PROPOSED"));
ToggleGroup group = new ToggleGroup();
group.getToggles().addAll(rbScheduled, rbProposed);
group.selectToggle(rbScheduled);
final VBox vBox = new VBox(
new Label(OTNBundle.getString("OTN.CONFLICT.QUESTION")),
sessionPane(scheduled, rbScheduled),
sessionPane(proposed, rbProposed));
vBox.getStyleClass().add("content");
setContent(vBox);
getButtons().addAll(
createButton(OTNBundle.getString("OTN.BUTTON.CANCEL"), () -> null),
createButton(OTNBundle.getString("OTN.BUTTON.SCHEDULE"), () -> rbProposed.isSelected() ? proposed: scheduled));
}
示例11: impl_drawNode
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
@Override
public Node impl_drawNode() {
try {
vb = FXMLLoader.load(resource);
} catch (Exception e) {
System.out.println("message: " + e.getMessage());
reportGetterFailure("exception thrown.");
}
LinkedList<ToggleGroup> toggleGroups = new LinkedList<ToggleGroup>();
for(Node child: vb.getChildren())
{
toggleGroups.add(((RadioButton) child).getToggleGroup());
}
for(int i = 0; i < toggleGroups.size() - 2; i ++)
{
if(!toggleGroups.get(i).equals(toggleGroups.get(i + 1)))
{
reportGetterFailure("failed.");
return redRectangle;
}
}
return retRec;
}
示例12: setupButton
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
private ToggleButton setupButton(ToggleGroup group, ComponentLauncherInfo componentInfo) {
ToggleButton button = new ToggleButton(componentInfo.name.getValue(), setupImageView(componentInfo.image));
button.setAlignment(Pos.CENTER_LEFT);
button.setToggleGroup(group);
button.setMinHeight(30);
button.setMaxWidth(Double.MAX_VALUE);
button.setOnAction(e -> {
if(button.isSelected()) {
modifiedSelection(componentInfo);
} else {
modifiedSelection(null);
}
});
GridPane.setHgrow(button, Priority.ALWAYS);
return button;
}
示例13: enumChoiceBox
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
private <T extends Enum> VBox enumChoiceBox(final Class<T> enumClass, final Enum currentValue) {
final T[] values = enumClass.getEnumConstants();
final List<RadioButton> buttons = new ArrayList<>();
final ToggleGroup toggleGroup = new ToggleGroup();
for (T value : values) {
final RadioButton button = new RadioButton(value.toString());
button.setToggleGroup(toggleGroup);
button.setSelected(value.equals(currentValue));
buttons.add(button);
}
final VBox result = new VBox();
result.setSpacing(10.0);
result.getChildren().addAll(buttons);
return result;
}
示例14: criaPainelSuperior
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
private HBox criaPainelSuperior() {
HBox hbTopo = new HBox(10);
hbTopo.setSpacing(10);
hbTopo.setAlignment(Pos.CENTER);
Transicoes[] transicoes = Transicoes.values();
// grupo para todas as transições
botoesTransicao = new ToggleGroup();
Stream.of(transicoes).map(t -> {
ToggleButton tb = new ToggleButton(t.name());
tb.setUserData(t);
tb.setToggleGroup(botoesTransicao);
return tb;
}).forEach(hbTopo.getChildren()::add);
botoesTransicao.getToggles().get(0).setSelected(true);
return hbTopo;
}
示例15: getActionToggleButton
import javafx.scene.control.ToggleGroup; //导入依赖的package包/类
public ToggleButton getActionToggleButton(GUIActions actionType, boolean hideActionText, ToggleGroup group) {
Action action = getAction(actionType);
ToggleButton button = ActionUtils.createToggleButton(action, hideActionText ? ActionTextBehavior.HIDE : ActionTextBehavior.SHOW);
if (hideActionText && action.getText() != null) {
Tooltip.install(button, new Tooltip(action.getText()));
// button.setTooltip(new Tooltip(action.getText()));
//// button.setText(null);
}
// Internally, ControlsFX duplicates graphics (or gives up) because Nodes can't appear multiple times the scene graph
// Consequently, we need to bind changes to the text fill here so that they filter through
if (button.getGraphic() instanceof Glyph) {
((Glyph)button.getGraphic()).textFillProperty().bind(((Glyph)action.getGraphic()).textFillProperty());
}
if (group != null)
button.setToggleGroup(group);
return button;
}