use of javafx.scene.control.Toggle in project financial by greatkendy123.
the class MyController method initAutoTestMode.
/**
* 启动测试模式
*
* @time 2017年11月11日
*/
private void initAutoTestMode() {
hbox_autoTestMode.setVisible(false);
ToggleGroup group = new ToggleGroup();
radio_autoTest_yes.setToggleGroup(group);
radio_autoTest_no.setToggleGroup(group);
radio_autoTest_yes.setUserData("是");
radio_autoTest_no.setUserData("否");
radio_autoTest_no.setSelected(true);
group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
public void changed(ObservableValue<? extends Toggle> ov, Toggle toggle, Toggle new_toggle) {
String autoTestMode = (String) group.getSelectedToggle().getUserData();
if ("是".equals(autoTestMode)) {
hbox_autoTestMode.setVisible(true);
} else {
hbox_autoTestMode.setVisible(false);
}
}
});
}
use of javafx.scene.control.Toggle in project POL-POM-5 by PhoenicisOrg.
the class SidebarToggleGroupBehavior method selectFirstToggleButton.
/**
* Ensures, that always a button is selected:
* - if because of an invalidation of the input list the selection is lost, the selection is reapplied
* - if no button is selected, select the first button
*/
private void selectFirstToggleButton() {
final ToggleGroup toggleGroup = getSkin().getToggleGroup();
if (toggleGroup.getSelectedToggle() == null && !toggleGroup.getToggles().isEmpty()) {
final E selectedElement = getControl().selectedElementProperty().getValue();
if (selectedElement != null && getControl().getElements().contains(selectedElement)) {
// 1 if an "all" button exists, 0 otherwise
final int offset = toggleGroup.getToggles().size() - getControl().getElements().size();
final int index = getControl().getElements().indexOf(getControl().selectedElementProperty().getValue());
// reselect the previously selected item
toggleGroup.selectToggle(toggleGroup.getToggles().get(offset + index));
} else {
final Toggle firstToggle = toggleGroup.getToggles().get(0);
// trigger the first item in the toggle group
if (firstToggle instanceof ToggleButton) {
((ToggleButton) firstToggle).fire();
}
}
}
}
Aggregations