本文整理汇总了Java中javafx.scene.control.MenuItem类的典型用法代码示例。如果您正苦于以下问题:Java MenuItem类的具体用法?Java MenuItem怎么用?Java MenuItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MenuItem类属于javafx.scene.control包,在下文中一共展示了MenuItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import javafx.scene.control.MenuItem; //导入依赖的package包/类
@Override
public void start(Stage stage) {
stage.setTitle("Vokabeltrainer");
Scene scene = new Scene(new VBox(), 400, 350);
scene.setFill(Color.OLDLACE);
MenuBar menuBar = new MenuBar();
// --- Menu File
Menu menuFile = new Menu("Vokabeln");
MenuItem sample = new MenuItem("Sample");
sample.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// Do stuff here
}
});
menuFile.getItems().add(sample);
// --- Menu Edit
Menu menuEdit = new Menu("Abfragemodus");
// --- Menu View
Menu menuView = new Menu("Statistik");
menuBar.getMenus().addAll(menuFile, menuEdit, menuView);
((VBox) scene.getRoot()).getChildren().addAll(menuBar);
stage.setScene(scene);
stage.show();
}
示例2: getContextMenu
import javafx.scene.control.MenuItem; //导入依赖的package包/类
@Override
public ContextMenu getContextMenu()
{
ContextMenu contextMenu = new ContextMenu();
ObjEntity objectEntity = (ObjEntity) getPropertyAdapter().getWrappedObject();
getPropertyAdapter().getDataMapAdapter().getDatabaseEntityAdapters().stream().forEach(databaseEntity ->
{
if (StringUtils.equals(databaseEntity.getName(), objectEntity.getDbEntityName()))
{
MenuItem jumpTo = new MenuItem("Jump To Database Entity: " + databaseEntity.getName());
jumpTo.setMnemonicParsing(false);
jumpTo.setOnAction(event ->
{
LOGGER.debug("Jumping to DB Entity: " + databaseEntity.getName());
});
contextMenu.getItems().add(jumpTo);
}
});
return contextMenu;
}
示例3: build
import javafx.scene.control.MenuItem; //导入依赖的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;
}
示例4: createURLLink
import javafx.scene.control.MenuItem; //导入依赖的package包/类
private void createURLLink(String pattern, String id, String icon) {
MenuItem tmsMenuItem = new MenuItem(id, FXUIUtils.getIcon(icon));
if (pattern != null && pattern.length() > 0) {
String url = String.format(pattern, id);
tmsMenuItem.setOnAction((event) -> {
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
});
} else {
tmsMenuItem.setDisable(true);
}
infoButton.getItems().add(tmsMenuItem);
}
示例5: fillContextMenu
import javafx.scene.control.MenuItem; //导入依赖的package包/类
@Override
@FXThread
public void fillContextMenu(@NotNull final NodeTree<?> nodeTree,
@NotNull final ObservableList<MenuItem> items) {
if (!(nodeTree instanceof ModelNodeTree)) return;
final T element = getElement();
final AssetLinkNode linkNode = findParent(element, AssetLinkNode.class::isInstance);
if (linkNode == null) {
final Menu createMenu = createCreationMenu(nodeTree);
if (createMenu != null) items.add(createMenu);
final Menu toolMenu = createToolMenu(nodeTree);
if (toolMenu != null) items.add(toolMenu);
}
if (linkNode == null || element == linkNode) {
items.add(new AddUserDataAction(nodeTree, this));
}
if (canRemove()) {
items.add(new RemoveNodeAction(nodeTree, this));
}
super.fillContextMenu(nodeTree, items);
}
示例6: getTagForMenu
import javafx.scene.control.MenuItem; //导入依赖的package包/类
private String getTagForMenu(MenuItem source) {
LinkedList<MenuItem> menuItems = new LinkedList<>();
while (source != null) {
menuItems.addFirst(source);
source = source.getParentMenu();
}
if (menuItems.getFirst() instanceof Menu) {
if (menuItems.size() >= 2) {
ownerNode = menuItems.get(1).getParentPopup().getOwnerNode();
return isMenuBar(ownerNode) ? "#menu" : "#contextmenu";
}
} else {
ownerNode = menuItems.getFirst().getParentPopup().getOwnerNode();
return "#contextmenu";
}
return null;
}
示例7: updateMenuItems
import javafx.scene.control.MenuItem; //导入依赖的package包/类
private void updateMenuItems() {
ToggleGroup group = new ToggleGroup();
List<MenuItem> items = new ArrayList<>();
for (Calendar calendar : getSkinnable().getCalendars()) {
RadioMenuItem item = new RadioMenuItem(calendar.getName());
Rectangle icon = new Rectangle(10, 10);
icon.setArcHeight(2);
icon.setArcWidth(2);
icon.getStyleClass().add(calendar.getStyle() + "-icon"); //$NON-NLS-1$
item.setGraphic(icon);
item.setDisable(calendar.isReadOnly());
item.setOnAction(evt -> getSkinnable().setCalendar(calendar));
group.getToggles().add(item);
items.add(item);
if (calendar.equals(getSkinnable().getCalendar())) {
item.setSelected(true);
}
}
button.getItems().setAll(items);
}
示例8: GoogleEntryAttendeeItem
import javafx.scene.control.MenuItem; //导入依赖的package包/类
public GoogleEntryAttendeeItem(EventAttendee attendee) {
this.attendee = Objects.requireNonNull(attendee);
optionalIcon = new Label();
optionalIcon.setOnMouseClicked(evt -> setOptional(!isOptional()));
optionalIcon.getStyleClass().add("button-icon");
optionalIcon.setTooltip(new Tooltip());
statusIcon = new Label();
name = new Label();
name.setMaxWidth(Double.MAX_VALUE);
setOptional(Boolean.TRUE.equals(attendee.getOptional()));
optionalProperty().addListener(obs -> updateIcon());
updateIcon();
removeButton = new Label();
removeButton.setGraphic(new FontAwesome().create(FontAwesome.Glyph.TRASH_ALT));
removeButton.getStyleClass().add("button-icon");
removeButton.setOnMouseClicked(evt -> removeAttendee(attendee));
HBox.setHgrow(optionalIcon, Priority.NEVER);
HBox.setHgrow(name, Priority.ALWAYS);
HBox.setHgrow(removeButton, Priority.NEVER);
getStyleClass().add("attendee-item");
getChildren().addAll(optionalIcon, statusIcon, name, removeButton);
ContextMenu menu = new ContextMenu();
MenuItem optionalItem = new MenuItem("Mark as optional");
optionalItem.setOnAction(evt -> setOptional(true));
MenuItem requiredItem = new MenuItem("Mark as required");
requiredItem.setOnAction(evt -> setOptional(false));
MenuItem removeItem = new MenuItem("Remove attendee");
removeItem.setOnAction(evt -> removeAttendee(attendee));
menu.getItems().addAll(optionalItem, requiredItem, new SeparatorMenuItem(), removeItem);
addEventHandler(CONTEXT_MENU_REQUESTED, evt -> menu.show(this, evt.getScreenX(), evt.getScreenY()));
}
示例9: subMenuPath
import javafx.scene.control.MenuItem; //导入依赖的package包/类
@Test public void subMenuPath() {
List<String> path = new ArrayList<>();
Platform.runLater(() -> {
Menu menuEdit = new Menu("Edit");
Menu menuEffect = new Menu("Picture Effect");
final MenuItem noEffects = new MenuItem("No Effects");
menuEdit.getItems().addAll(menuEffect, noEffects);
MenuItem add = new MenuItem("Shuffle");
menuEffect.getItems().addAll(add);
RFXMenuItem rfxMenuItem = new RFXMenuItem(null, null);
path.add(rfxMenuItem.getSelectedMenuPath(add));
});
new Wait("Waiting for menu selection path") {
@Override public boolean until() {
return path.size() > 0;
}
};
AssertJUnit.assertEquals("Edit>>Picture Effect>>Shuffle", path.get(0));
}
示例10: populateExamples
import javafx.scene.control.MenuItem; //导入依赖的package包/类
private void populateExamples() {
val map = new LinkedHashMap<String, String>();
map.put("HotaruFX Logo", "hotarufx-logo.hfx");
map.put("Font Awesome Icons", "font-awesome.hfx");
map.put("HSV Color", "hsv.hfx");
map.put("Line", "line.hfx");
map.put("Rectangle", "rectangle.hfx");
map.put("Round Rectangle", "round-rect.hfx");
map.put("Font", "font.hfx");
map.put("Image", "image.hfx");
map.put("Image Rotate & Zoom", "image_rotate_zoom.hfx");
map.put("Text Clipping", "clip-text.hfx");
map.put("Blend Modes", "blend-modes.hfx");
map.put("Stroke Ants", "stroke-ants.hfx");
examplesMenu.getItems().clear();
for (val entry : map.entrySet()) {
val item = new MenuItem(entry.getKey());
item.setOnAction(e -> openExample("/examples/" + entry.getValue()));
examplesMenu.getItems().add(item);
}
}
示例11: buildMenuItem
import javafx.scene.control.MenuItem; //导入依赖的package包/类
private void buildMenuItem() {
for (int i = 0; i < this.batpack.getModuleCount(); i++) {
Group module = batteryModules.get(i);
String labelText = ((Label) module.getChildren().get(3)).getText();
MenuItem menuItem = new MenuItem(labelText);
menuItem.setId(Integer.toString(i));
EventHandler<ActionEvent> updateCells;
updateCells = (event) -> {
MenuItem menu = (MenuItem) event.getSource();
int id = Integer.parseInt(menu.getId());
moduleChooser.setText("module " + (id + 1));
updateCells(id);
};
menuItem.setOnAction(updateCells);
List<MenuItem> menuItems = new ArrayList<>();
menuItems.add(menuItem);
moduleChooser.getItems().addAll(menuItems);
}
}
示例12: TextPaneMenu
import javafx.scene.control.MenuItem; //导入依赖的package包/类
public TextPaneMenu(TextArea textArea) {
this.textArea = textArea;
MenuItem copy = new MenuItem("_Copy");
this.setStyle(FontUtils.setUIFont(this.getStyle()));
copy.setMnemonicParsing(true);
copy.setOnAction(e -> {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection s = new StringSelection(
textArea.getSelectedText()
);
clipboard.setContents(s, null);
});
copy.setGraphic(new ImageView(ImageUtils.copyImage));
getItems().addAll(copy);
}
示例13: AsciiPaneMenu
import javafx.scene.control.MenuItem; //导入依赖的package包/类
public AsciiPaneMenu(TextArea textArea) {
this.textArea = textArea;
MenuItem copy = new MenuItem("_Copy");
this.setStyle(FontUtils.setUIFont(this.getStyle()));
copy.setMnemonicParsing(true);
copy.setOnAction(e -> {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection s = new StringSelection(
textArea.getSelectedText().replace("\n", "")
);
clipboard.setContents(s, null);
});
copy.setGraphic(new ImageView(ImageUtils.copyImage));
getItems().addAll(copy);
}
示例14: load
import javafx.scene.control.MenuItem; //导入依赖的package包/类
@Override
public void load() {
super.load();
Platform.runLater(new Runnable() { // this will run initFX as JavaFX-Thread
@Override
public void run() {
webView.setContextMenuEnabled(false);
contextMenu = new ContextMenu();
open = new MenuItem("Open in browser");
addActionListener();
addContextMenuListener();
contextMenu.getItems().addAll(open);
}
});
}
示例15: handle
import javafx.scene.control.MenuItem; //导入依赖的package包/类
@Override
public void handle(ActionEvent event)
{
GoliathOUFX.scene.getStylesheets().remove(0);
switch(((MenuItem)event.getSource()).getText())
{
case "Magma":
GoliathOUFX.scene.getStylesheets().add("skins/Goliath-Magma.css");
break;
case "Arc":
GoliathOUFX.scene.getStylesheets().add("skins/Goliath-Arc.css");
break;
}
}