本文整理汇总了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;
}