本文整理汇总了Java中javafx.scene.control.ToggleButton类的典型用法代码示例。如果您正苦于以下问题:Java ToggleButton类的具体用法?Java ToggleButton怎么用?Java ToggleButton使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ToggleButton类属于javafx.scene.control包,在下文中一共展示了ToggleButton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
VBox root = new VBox();
Label counterLabel = new Label("");
ToggleButton startStopButton = new ToggleButton();
// Multicast the ToggleButton's true/false selected state
Observable<Boolean> selectedStates =
JavaFxObservable.valuesOf(startStopButton.selectedProperty())
.publish()
.autoConnect(2);
// Using switchMap() with ToggleButton's selected state willdrive
// whether to kick off an Observable.interval(),
// or dispose() it by switching to empty Observable
selectedStates.switchMap(selected -> {
if (selected)
return Observable.interval(1,
TimeUnit.MILLISECONDS);
else
return Observable.empty();
}).observeOn(JavaFxScheduler.platform()) // Observe on JavaFX UI thread
.map(Object::toString)
.subscribe(counterLabel::setText);
// Change ToggleButton's text depending on its state
selectedStates.subscribe(selected ->
startStopButton.setText(selected ? "STOP" :
"START")
);
root.getChildren().addAll(counterLabel, startStopButton);
stage.setScene(new Scene(root));
stage.show();
}
示例2: WeekPage
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
/**
* Constructs a new week page.
*/
public WeekPage() {
getStyleClass().add("week-page"); //$NON-NLS-1$
setDateTimeFormatter(DateTimeFormatter.ofPattern(Messages.getString("WeekPage.DATE_FORMAT"))); //$NON-NLS-1$
this.detailedWeekView = new DetailedWeekView();
ToggleButton layoutButton = new ToggleButton();
layoutButton.setTooltip(new Tooltip(Messages.getString("WeekPage.TOOLTIP_LAYOUT"))); //$NON-NLS-1$
layoutButton.setId("layout-button");
Text layoutIcon = FontAwesomeIconFactory.get().createIcon(FontAwesomeIcon.TABLE);
layoutIcon.getStyleClass().addAll("button-icon", "layout-button-icon"); //$NON-NLS-1$ //$NON-NLS-2$
layoutButton.setGraphic(layoutIcon);
layoutButton.setSelected(getLayout().equals(Layout.SWIMLANE));
layoutButton.setOnAction(evt -> {
if (layoutButton.isSelected()) {
setLayout(Layout.SWIMLANE);
} else {
setLayout(Layout.STANDARD);
}
});
showLayoutButtonProperty().addListener(it -> updateToolBarControls(layoutButton));
updateToolBarControls(layoutButton);
}
示例3: loadModes
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
private void loadModes(){
modesBox.getChildren().clear();
int count = Dashboard.getModeSelectorControl().getModesCount();
modesButtons = new ToggleButton[count];
for (int i = 0; i < modesButtons.length; i++) {
modesButtons[i] = new ToggleButton(
Dashboard.getModeSelectorControl().getMode(i).name);
modesButtons[i].setMinSize(130, 20);
modesButtons[i].setToggleGroup(modesToggleGroup);
modesBox.getChildren().add(modesButtons[i]);
}
if(count > 0)
modesButtons[0].setSelected(true);
}
示例4: createToolbar
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Override
@FXThread
protected void createToolbar(@NotNull final HBox container) {
super.createToolbar(container);
lightButton = new ToggleButton();
lightButton.setTooltip(new Tooltip(Messages.SCENE_FILE_EDITOR_ACTION_SHOW_LIGHTS));
lightButton.setGraphic(new ImageView(Icons.LIGHT_16));
lightButton.setSelected(true);
lightButton.selectedProperty().addListener((observable, oldValue, newValue) -> changeLight(newValue));
audioButton = new ToggleButton();
audioButton.setTooltip(new Tooltip(Messages.SCENE_FILE_EDITOR_ACTION_SHOW_AUDIO));
audioButton.setGraphic(new ImageView(Icons.AUDIO_16));
audioButton.setSelected(true);
audioButton.selectedProperty().addListener((observable, oldValue, newValue) -> changeAudio(newValue));
DynamicIconSupport.addSupport(lightButton, audioButton);
FXUtils.addClassesTo(lightButton, audioButton, CSSClasses.FILE_EDITOR_TOOLBAR_BUTTON);
FXUtils.addToPane(lightButton, container);
FXUtils.addToPane(audioButton, container);
}
示例5: 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);
}
示例6: createBottomNavigation
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
private BottomNavigation createBottomNavigation(final Speaker activeSpeaker) {
BottomNavigation bottomNavigation = new BottomNavigation();
final ToggleButton infoButton = bottomNavigation.createButton(OTNBundle.getString("OTN.BUTTON.INFO"), MaterialDesignIcon.INFO.graphic(), e -> {
// when clicked create a label in a scrollpane. Label will contain
// the speaker summary
Label speakerSummary = new Label(activeSpeaker.getSummary());
speakerSummary.setWrapText(true);
speakerSummary.getStyleClass().add("speaker-summary");
speakerView.setCenter(createScrollPane(speakerSummary));
});
final ToggleButton sessionsButton = bottomNavigation.createButton(OTNBundle.getString("OTN.BUTTON.SESSIONS"), MaterialDesignIcon.EVENT_NOTE.graphic(), e -> {
// when clicked we create a pane containing all sessions.
speakerView.setCenter(createSessionsListView(activeSpeaker));
});
bottomNavigation.getActionItems().addAll(infoButton, sessionsButton);
// listen to the selected toggle so we ensure it is selected when the view is returned to
infoButton.getToggleGroup().selectedToggleProperty().addListener((o,ov,nv) -> lastSelectedButton = nv);
infoButton.setSelected(true);
return bottomNavigation;
}
示例7: handle
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Override
public void handle(final MouseEvent event) {
final ToggleButton button = (ToggleButton) event.getSource();
if (button.isSelected()) {
final FileChooser fileChooser = new FileChooser();
fileChooser.setInitialFileName("record.wav");
fileChooser.setInitialDirectory(new File(System.getProperty("java.io.tmpdir")));
fileChooser.setTitle("Save File");
final File fileToWrite = fileChooser.showSaveDialog(CoreController.getStage());
componentOut.getLineOut().setFileToWrite(fileToWrite);
componentOut.getLineOut().startRecord();
button.setSelected(true);
button.setText("Stop");
button.setTextFill(Color.RED);
} else {
componentOut.getLineOut().stopRecord();
button.setSelected(false);
button.setText("Record");
}
event.consume();
}
示例8: getConstructorPage
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Override
protected List<Labeled> getConstructorPage() {
List<Labeled> list = new ArrayList<Labeled>();
ToggleButton default_button = new ToggleButton(DEFAULT_BUTTON);
defaultLayout.apply(default_button);
if (!default_button.getText().equals(DEFAULT_BUTTON)) {
reportGetterFailure("new ToggleButton(DEFAULT_LABEL)");
} else {
list.add(default_button);
}
Rectangle rectangle = new Rectangle(10, 10, Color.rgb(200, 100, 100));
ToggleButton graphic_button = new ToggleButton(GRAPHICS_BUTTON, rectangle);
defaultLayout.apply(graphic_button);
if (!graphic_button.getText().equals(GRAPHICS_BUTTON) || graphic_button.getGraphic() != rectangle) {
reportGetterFailure("new ToggleButton(GRAPHICS_LABEL, rectangle)");
} else {
list.add(graphic_button);
}
return list;
}
示例9: setup
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Override
protected TestNode setup() {
TestNode root = new TestNode();
defFill(root);
ArrayList<Change<Labeled>> list = new ArrayList<Change<Labeled>>();
list.add(new Change<Labeled>(Pages.setSelected.name()) {
public void apply(Labeled labeled) {
ToggleButton button = (ToggleButton) labeled;
button.setSelected(true);
if (button.isSelected() != true) {
reportGetterFailure(getMarker());
}
}
});
root.add(new Page(list), Pages.setSelected.name());
return root;
}
示例10: prepareScene
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
private void prepareScene(final Stage stage) {
testedStage = stage;
PropertiesTable tb = new PropertiesTable(testedStage);
PropertyTablesFactory.explorePropertiesList(testedStage, tb);
final ToggleButton toggle = new ToggleButton("Fullscreen state : false");
toggle.setSelected(false);
toggle.selectedProperty().addListener(new ChangeListener<Boolean>(){
public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
toggle.setText("Fullscreen state : " + t1);
stage.setFullScreen(t1);
}
});
VBox vb = (VBox) getRoot();
vb.setPadding(new Insets(5, 5, 5, 5));
vb.setStyle("-fx-border-color : green;");
vb.getChildren().addAll(tb, toggle);
}
示例11: informationAlertBasicWithButtonsTest
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Test(timeout = 300000)
public void informationAlertBasicWithButtonsTest() throws Throwable {
for (StageStyle s : StageStyle.values()) {
Wrap<? extends Node> styleToggleButton = parent.lookup(ToggleButton.class, new ByText<ToggleButton>(s.toString())).wrap();
click(styleToggleButton, InputType.MOUSE);
for (ButtonType b : types) {
addButton(b.getText());
Wrap<? extends Node> button = parent.lookup(Button.class, new ByText<Button>(BUTTON_SHOW_INFO_TEXT)).wrap();
click(button, InputType.MOUSE);
Thread.sleep(DEFAULT_DELAY);
checkScreenshot("informationAlertBasicWithButtonsTest" + s + "_" + b + "Test", scene);
closeDialogWindowByClickingButton();
Thread.sleep(DEFAULT_DELAY);
throwScreenshotError();
}
deselectButtons();
}
}
示例12: confirmationAlertBasicWithButtonsTest
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Test(timeout = 300000)
public void confirmationAlertBasicWithButtonsTest() throws Throwable {
for (StageStyle s : StageStyle.values()) {
Wrap<? extends Node> styleToggleButton = parent.lookup(ToggleButton.class, new ByText<ToggleButton>(s.toString())).wrap();
click(styleToggleButton, InputType.MOUSE);
for (ButtonType b : types) {
addButton(b.getText());
Wrap<? extends Node> button = parent.lookup(Button.class, new ByText<Button>(BUTTON_SHOW_CONFIRM_TEXT)).wrap();
click(button, InputType.MOUSE);
Thread.sleep(DEFAULT_DELAY);
checkScreenshot("confirmationAlertBasicWithButtonsTest" + s + "_" + b + "Test", scene);
closeDialogWindowByClickingButton();
Thread.sleep(DEFAULT_DELAY);
throwScreenshotError();
}
deselectButtons();
}
}
示例13: warningAlertBasicWithButtonsTest
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Test(timeout = 300000)
public void warningAlertBasicWithButtonsTest() throws Throwable {
for (StageStyle s : StageStyle.values()) {
Wrap<? extends Node> styleToggleButton = parent.lookup(ToggleButton.class, new ByText<ToggleButton>(s.toString())).wrap();
click(styleToggleButton, InputType.MOUSE);
for (ButtonType b : types) {
addButton(b.getText());
Wrap<? extends Node> button = parent.lookup(Button.class, new ByText<Button>(BUTTON_SHOW_WARNING_TEXT)).wrap();
click(button, InputType.MOUSE);
Thread.sleep(DEFAULT_DELAY);
checkScreenshot("warningAlertBasicWithButtonsTest" + s + "_" + b + "Test", scene);
closeDialogWindowByClickingButton();
Thread.sleep(DEFAULT_DELAY);
throwScreenshotError();
}
deselectButtons();
}
}
示例14: errorAlertBasicWithButtonsTest
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Test(timeout = 300000)
public void errorAlertBasicWithButtonsTest() throws Throwable {
for (StageStyle s : StageStyle.values()) {
Wrap<? extends Node> styleToggleButton = parent.lookup(ToggleButton.class, new ByText<ToggleButton>(s.toString())).wrap();
click(styleToggleButton, InputType.MOUSE);
for (ButtonType b : types) {
addButton(b.getText());
Wrap<? extends Node> button = parent.lookup(Button.class, new ByText<Button>(BUTTON_SHOW_ERROR_TEXT, StringComparePolicy.EXACT)).wrap();
click(button, InputType.MOUSE);
Thread.sleep(DEFAULT_DELAY);
checkScreenshot("errorAlertBasicWithButtonsTest" + s + "_" + b + "Test", scene);
closeDialogWindowByClickingButton();
Thread.sleep(DEFAULT_DELAY);
throwScreenshotError();
}
deselectButtons();
}
}
示例15: informationAlertResponceTest
import javafx.scene.control.ToggleButton; //导入依赖的package包/类
@Test(timeout = 300000)
public void informationAlertResponceTest() throws Throwable {
for (StageStyle s : StageStyle.values()) {
Wrap<? extends Node> styleToggleButton = parent.lookup(ToggleButton.class, new ByText<ToggleButton>(s.toString())).wrap();
click(styleToggleButton, InputType.MOUSE);
for (ButtonType b : types) {
addButton(b.getText());
Wrap<? extends Node> button = parent.lookup(Button.class, new ByText<Button>(BUTTON_SHOW_INFO_TEXT)).wrap();
click(button, InputType.MOUSE);
closeDialogWindowByClickingButton(b.getText());
Wrap<? extends Node> resultField = parent.lookup(TextField.class, new ByID<TextField>(RESULT_FIELD_ID)).wrap();
resultField.waitProperty(Wrap.TEXT_PROP_NAME, b.getText());
Thread.sleep(DEFAULT_DELAY);
}
deselectButtons();
}
}