本文整理匯總了Java中javafx.scene.control.Button.setContextMenu方法的典型用法代碼示例。如果您正苦於以下問題:Java Button.setContextMenu方法的具體用法?Java Button.setContextMenu怎麽用?Java Button.setContextMenu使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.control.Button
的用法示例。
在下文中一共展示了Button.setContextMenu方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: build
import javafx.scene.control.Button; //導入方法依賴的package包/類
public Button build(String name, Association association) {
EventBus eventBus = toolBox.getEventBus();
Button button = new JFXButton(name);
button.setUserData(association);
button.getStyleClass().add("abpanel-button");
button.setOnAction(event -> {
ArrayList<Annotation> annotations = new ArrayList<>(toolBox.getData().getSelectedAnnotations());
eventBus.send(new CreateAssociationsCmd(association, annotations));
});
button.setTooltip(new Tooltip(association.toString()));
ContextMenu contextMenu = new ContextMenu();
MenuItem deleteButton = new MenuItem(toolBox.getI18nBundle().getString("cbpanel.conceptbutton.delete"));
deleteButton.setOnAction(event ->
((Pane) button.getParent()).getChildren().remove(button));
contextMenu.getItems().addAll(deleteButton);
button.setContextMenu(contextMenu);
return button;
}
示例2: build
import javafx.scene.control.Button; //導入方法依賴的package包/類
public Button build(String name) {
Button button = new JFXButton(name);
button.setUserData(USERDATA);
button.getStyleClass().add("cbpanel-button");
button.setOnAction(event ->
eventBus.send(new CreateAnnotationFromConceptCmd(button.getText())));
// Add contextMenu
ContextMenu contextMenu = new ContextMenu();
MenuItem showInTreeItem = new MenuItem(i18n.getString("cbpanel.conceptbutton.findconcept"));
showInTreeItem.setOnAction(event -> {
ShowConceptInTreeViewMsg msg = new ShowConceptInTreeViewMsg(button.getText());
eventBus.send(msg);
});
MenuItem deleteButton = new MenuItem(i18n.getString("cbpanel.conceptbutton.delete"));
deleteButton.setOnAction(event ->
((Pane) button.getParent()).getChildren().remove(button));
contextMenu.getItems().addAll(showInTreeItem, deleteButton);
button.setContextMenu(contextMenu);
button.setOnDragDetected(evt -> {
if (button.getText() != null) {
// Drag the string name to some target.
Dragboard db = button.startDragAndDrop(TransferMode.MOVE);
ClipboardContent content = new ClipboardContent();
content.putString(name);
db.setContent(content);
evt.consume();
}
});
conceptService.findDetails(name)
.thenApply(opt -> {
if (!opt.isPresent()) {
Platform.runLater(() -> {
button.getStyleClass().add("button-invalid");
button.setOnAction(e -> {});
});
}
return null;
});
return button;
}