Example usage for javafx.scene.control MenuItem MenuItem

List of usage examples for javafx.scene.control MenuItem MenuItem

Introduction

In this page you can find the example usage for javafx.scene.control MenuItem MenuItem.

Prototype

public MenuItem() 

Source Link

Document

Constructs a MenuItem with no display text.

Usage

From source file:net.sourceforge.pmd.util.fxdesigner.MainDesignerController.java

private void updateRecentFilesMenu() {
    List<MenuItem> items = new ArrayList<>();
    List<File> filesToClear = new ArrayList<>();

    for (final File f : recentFiles) {
        if (f.exists() && f.isFile()) {
            CustomMenuItem item = new CustomMenuItem(new Label(f.getName()));
            item.setOnAction(e -> loadSourceFromFile(f));
            item.setMnemonicParsing(false);
            Tooltip.install(item.getContent(), new Tooltip(f.getAbsolutePath()));
            items.add(item);/*from   w w w  .  j a  v a2  s .c o m*/
        } else {
            filesToClear.add(f);
        }
    }
    recentFiles.removeAll(filesToClear);

    if (items.isEmpty()) {
        openRecentMenu.setDisable(true);
        return;
    }

    Collections.reverse(items);

    items.add(new SeparatorMenuItem());
    MenuItem clearItem = new MenuItem();
    clearItem.setText("Clear menu");
    clearItem.setOnAction(e -> {
        recentFiles.clear();
        openRecentMenu.setDisable(true);
    });
    items.add(clearItem);

    openRecentMenu.getItems().setAll(items);
}