本文整理汇总了Java中javafx.scene.control.ToggleButton.setToggleGroup方法的典型用法代码示例。如果您正苦于以下问题:Java ToggleButton.setToggleGroup方法的具体用法?Java ToggleButton.setToggleGroup怎么用?Java ToggleButton.setToggleGroup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.ToggleButton
的用法示例。
在下文中一共展示了ToggleButton.setToggleGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initItems
import javafx.scene.control.ToggleButton; //导入方法依赖的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);
}
示例2: setupButton
import javafx.scene.control.ToggleButton; //导入方法依赖的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;
}
示例3: getActionToggleButton
import javafx.scene.control.ToggleButton; //导入方法依赖的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;
}
示例4: addTexture
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
private void addTexture(final TerrainTexture tex, final boolean isGlobal) {
final Canvas preview = new Canvas(64, 32);
final GraphicsContext gc = preview.getGraphicsContext2D();
gc.setFill(tex.samplePaint);
gc.fillRect(0, 0, 64, 32);
final ToggleButton t = new ToggleButton("", preview);
t.setFocusTraversable(false);
t.setToggleGroup(toolsGroup);
t.setContextMenu(new ToolContextMenu(this, AssetType.TEXTURE, tex.id, isGlobal));
t.setOnAction(event -> {
if (t.isSelected()) canvas.setTool(new TerrainTextureTool(tex));
else canvas.setTool(null);
});
if (isGlobal) {
textures.global.getChildren().add(t);
textureButtonsG.put(tex.id, t);
} else {
textures.local.getChildren().add(t);
textureButtonsL.put(tex.id, t);
}
}
示例5: makeSpriteButton
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
private ToggleButton makeSpriteButton(
final SpriteInfo sprite,
final Canvas preview,
final FacingDirection direction,
final ToolContextMenu menu
) {
final ToggleButton t = new ToggleButton("", preview);
t.setFocusTraversable(false);
t.setToggleGroup(toolsGroup);
t.setOnAction(event -> {
if (t.isSelected()) canvas.setTool(new SpriteTool(sprite, direction));
else canvas.setTool(null);
});
if (menu != null) t.setContextMenu(menu);
return t;
}
示例6: makeCliffButton
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
private ToggleButton makeCliffButton(
final CliffTexture tex, final Canvas canvas,
final SlopeType slope, final int elevation, final ToolContextMenu menu
) {
final GraphicsContext gc = canvas.getGraphicsContext2D();
gc.translate(0, (1 - elevation) * 16);
gc.scale(1.0d/4.0d, 1.0d/4.0d);
try {
(new Tile(elevation, slope, global.getTerrain("blank"), tex))
.render(gc, CameraAngle.UL);
} catch (CorruptDataException e) {
throw new RuntimeException("Missing blank texture");
}
final ToggleButton t = new ToggleButton("", canvas);
t.setFocusTraversable(false);
t.setToggleGroup(toolsGroup);
if (menu != null) t.setContextMenu(menu);
return t;
}
示例7: ContextSortingPane
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
/**
* Constructor for a Pane with Toogle Buttons.
* @param width width of the parent
*/
public ContextSortingPane(final double width) {
final ToggleGroup toggleGroup = new ToggleGroup();
final ToggleButton locationBtn = new ToggleButton("Location");
locationBtn.setToggleGroup(toggleGroup);
locationBtn.setMaxWidth(Double.MAX_VALUE);
locationBtn.setPrefWidth(width / 2);
final ToggleButton functionBtn = new ToggleButton("Function");
functionBtn.setToggleGroup(toggleGroup);
functionBtn.setMaxWidth(Double.MAX_VALUE);
functionBtn.setPrefWidth(width / 2);
//CHECKSTYLE.OFF: MultipleStringLiterals
locationBtn.getStyleClass().addAll("visible-lg", "visible-md", "visible-sm", "visible-xs");
functionBtn.getStyleClass().addAll("visible-lg", "visible-md", "visible-sm", "visible-xs");
//CHECKSTYLE.ON: MultipleStringLiterals
this.setToggleGroup(toggleGroup);
this.getButtons().addAll(locationBtn, functionBtn);
this.setMaxWidth(Double.MAX_VALUE);
//this.setPrefWidth(width);
this.setPadding(new Insets(Constants.INSETS, Constants.INSETS, Constants.INSETS, Constants.INSETS));
}
示例8: ToggleButtonSample
import javafx.scene.control.ToggleButton; //导入方法依赖的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);
}
示例9: start
import javafx.scene.control.ToggleButton; //导入方法依赖的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());
}
示例10: makeMenuBar
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
private HBox makeMenuBar() {
ToggleButton tb1 = new ToggleButton("MAIN MENU");
ToggleButton tb2 = new ToggleButton("OPTIONS");
ToggleButton tb3 = new ToggleButton("EXTRA");
tb1.setFont(FXGL.getUIFactory().newFont(18));
tb2.setFont(FXGL.getUIFactory().newFont(18));
tb3.setFont(FXGL.getUIFactory().newFont(18));
ToggleGroup group = new ToggleGroup();
tb1.setToggleGroup(group);
tb2.setToggleGroup(group);
tb3.setToggleGroup(group);
tb1.setUserData(menuBody);
tb2.setUserData(makeOptionsMenu());
tb3.setUserData(makeExtraMenu());
group.selectedToggleProperty().addListener((obs, old, newToggle) -> {
if (newToggle == null) {
group.selectToggle(old);
return;
}
switchMenuTo((Node)newToggle.getUserData());
});
group.selectToggle(tb1);
HBox hbox = new HBox(10, tb1, tb2, tb3);
hbox.setAlignment(Pos.TOP_CENTER);
return hbox;
}
示例11: ToggleButtonGroup
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
public ToggleButtonGroup(ToggleButton ... toggleButtons) {
this.toggleButtons = toggleButtons;
for (ToggleButton toggleButton : toggleButtons) {
toggleButton.setToggleGroup(this);
}
selectToggle(toggleButtons[0]);
}
示例12: getNode
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
public static Node getNode(){
VBox vb = new VBox();
HBox hb = new HBox();
final ToggleGroup tg = new ToggleGroup();
ToggleButton tb1 = new ToggleButton("Blue");
tb1.setUserData(Color.BLUE);
tb1.setToggleGroup(tg);
hb.getChildren().add(tb1);
ToggleButton tb2 = new ToggleButton("Green");
tb2.setUserData(Color.GREEN);
tb2.setToggleGroup(tg);
hb.getChildren().add(tb2);
ToggleButton tb3 = new ToggleButton("Yellow");
tb3.setUserData(Color.YELLOW);
tb3.setToggleGroup(tg);
hb.getChildren().add(tb3);
final Rectangle rect = new Rectangle(240, 100);
tg.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
@Override
public void changed(ObservableValue<? extends Toggle> arg0, Toggle arg1, Toggle arg2) {
if(tg.selectedToggleProperty()!=null){
rect.setFill( (Paint)tg.getSelectedToggle().getUserData());
}
}
});
vb.getChildren().add(hb);
vb.getChildren().add(rect);
return vb;
}
示例13: resetToggleGroup
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
private void resetToggleGroup() {
for (Node overlay : overlayViewFlowPane.getChildren()) {
ToggleButton overlayButton = (ToggleButton) overlay;
if (overlayButton.getToggleGroup() == null)
overlayButton.setToggleGroup(overlayToggleGroup);
}
}
示例14: AddAgentsToMapTitledPane
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
public AddAgentsToMapTitledPane(GeographicalMarketPresentation geographicalMarketPresentation, ControllableGeographicalScenario scenario) {
normalSelection = new ToggleButton(SELECT_BUTTON_STRING);
addOilPump = initializeButton(ADD_FIRM_BUTTON_STRING, GeographicalFirmPortrait.OIL_IMAGE);
addHousehold = initializeButton(ADD_HOUSEHOLD_BUTTON_STRING, GeographicalCustomerPortrait.CUSTOMER_IMAGE);
mouseSelection = new ToggleGroup();
normalSelection.setToggleGroup(mouseSelection);
addOilPump.setToggleGroup(mouseSelection);
addHousehold.setToggleGroup(mouseSelection);
//default to normal selection
mouseSelection.selectToggle(normalSelection);
currentMouseMode = new SimpleObjectProperty<>(MouseMode.SELECTION);
//create the mouse mode "actuator"
mouseModeSwitcher = new MouseModeSwitcher(currentMouseMode,geographicalMarketPresentation,scenario);
//start listening
mouseSelection.selectedToggleProperty().addListener(this);
currentMouseMode.addListener(this);
//add the buttons to the accordion
HBox toggleContainer = new HBox(normalSelection,addOilPump,addHousehold);
super.setContent(toggleContainer);
super.setText(PANE_TITLE);
}
示例15: createToggleButton
import javafx.scene.control.ToggleButton; //导入方法依赖的package包/类
private ToggleButton createToggleButton(ToggleGroup grp, String styleClass, Runnable action, String toolTip) {
ToggleButton button = new ToggleButton();
button.setToggleGroup(grp);
button.getStyleClass().add(styleClass);
button.setOnAction(evt -> {
action.run();
area.requestFocus();
});
button.setPrefWidth(25);
button.setPrefHeight(25);
if (toolTip != null) {
button.setTooltip(new Tooltip(toolTip));
}
return button;
}