public class CheckMenuItem extends MenuItem
選択状態と選択解除状態の切替えが可能なMenuItem。 MenuコントロールまたはContextMenuコントロールとともに使用することが想定されています。
CheckMenuItemの作成およびMenuへの挿入を次に示します。
final subsystem1 = new CheckMenuItem("Enabled");
subsystem1.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
System.out.println("subsystem1 #1 Enabled!");
}
});
Menu subsystemsMenu = new Menu("Subsystems");
subsystemsMenu.add(subsystem1);
前述のアプローチでは、CheckMenuItemの定義をMenuから分離していますが、必ずしもそのようにする必要はありません。
CheckMenuItemの現在の状態を確認するには、selectedのブール値を参照する必要があります。 ユースケースの例は、次のようになります。
final checkMenuItem = new CheckMenuItem("Show Widget");
subsystem1.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
System.out.println("Show the widget!");
}
});
private final BooleanProperty widgetShowing();
public final boolean isWidgetShowing() { return widgetShowing.get(); )
public final void setWidgetShowing(boolean value) {
widgetShowingProperty().set(value);
}
public final BooleanProperty widgetShowingProperty() {
if (widgetShowing == null) {
widgetShowing = new SimpleBooleanProperty(this, "widgetShowing", true);
}
return widgetShowing;
}
widgetShowing.bind(checkMenuItem.selected);
一般に、CheckMenuItemは、選択されると、MenuItemグラフィック用に通常確保されている領域にチェックマークまたは目盛を表示するようにレンダリングされます。 これは、指定されたスキンおよびスタイル設定に応じて変わります。
Menu、MenuItem、RadioMenuItem| Type | プロパティと説明 |
|---|---|
BooleanProperty |
selected
このCheckMenuItemの現在の状態を表します。
|
accelerator, disable, graphic, id, mnemonicParsing, onAction, onMenuValidation, parentMenu, parentPopup, style, text, visibleMENU_VALIDATION_EVENT| コンストラクタと説明 |
|---|
CheckMenuItem()
* コンストラクタ * *
|
CheckMenuItem(String text)
CheckMenuItemを構築し、指定されたテキストを使用して表示テキストを設定します。
|
CheckMenuItem(String text, Node graphic)
CheckMenuItemを構築し、指定されたテキストを使用して表示テキストを設定し、グラフィック
Nodeを指定されたノードに設定します。 |
| 修飾子と型 | メソッドと説明 |
|---|---|
boolean |
isSelected()
プロパティselectedの値を取得します。
|
BooleanProperty |
selectedProperty()
このCheckMenuItemの現在の状態を表します。
|
void |
setSelected(boolean value)
プロパティselectedの値を設定します。
|
acceleratorProperty, addEventHandler, buildEventDispatchChain, disableProperty, fire, getAccelerator, getCssMetaData, getGraphic, getId, getOnAction, getOnMenuValidation, getParentMenu, getParentPopup, getProperties, getPseudoClassStates, getStyle, getStyleableParent, getStyleClass, getText, getTypeSelector, getUserData, graphicProperty, idProperty, isDisable, isMnemonicParsing, isVisible, mnemonicParsingProperty, onActionProperty, onMenuValidationProperty, parentMenuProperty, parentPopupProperty, removeEventHandler, setAccelerator, setDisable, setGraphic, setId, setMnemonicParsing, setOnAction, setOnMenuValidation, setParentMenu, setParentPopup, setStyle, setText, setUserData, setVisible, styleProperty, textProperty, toString, visiblePropertypublic final BooleanProperty selectedProperty
isSelected()、setSelected(boolean)public CheckMenuItem()
public CheckMenuItem(String text)
public final void setSelected(boolean value)
public final boolean isSelected()
public final BooleanProperty selectedProperty()
isSelected()、setSelected(boolean)Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.