Example usage for javax.swing JMenuItem setBorder

List of usage examples for javax.swing JMenuItem setBorder

Introduction

In this page you can find the example usage for javax.swing JMenuItem setBorder.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.")
public void setBorder(Border border) 

Source Link

Document

Sets the border of this component.

Usage

From source file:com.haulmont.cuba.desktop.sys.MenuBuilder.java

private void createMenuBarItem(JMenuBar menuBar, MenuItem item) {
    String caption = menuConfig.getItemCaption(item.getId());
    if (!item.getChildren().isEmpty() || item.isMenu()) {
        final JMenu jMenu = new JMenu(caption);
        jMenu.addMenuListener(new MenuListener() {
            @Override//from w  w  w . ja va2 s . c o m
            public void menuSelected(MenuEvent e) {
                jMenu.requestFocus();
            }

            @Override
            public void menuDeselected(MenuEvent e) {
            }

            @Override
            public void menuCanceled(MenuEvent e) {
            }
        });
        jMenu.setName(item.getId());
        menuBar.add(jMenu);
        createSubMenu(jMenu, item);
    } else {
        JMenuItem jMenuItem = new JMenuItem(caption);
        jMenuItem.setName(item.getId());
        //todo remove hardcoded border
        jMenuItem.setBorder(BorderFactory.createEmptyBorder(1, 4, 2, 4));
        assignShortcut(jMenuItem, item);
        jMenuItem.setMaximumSize(
                new Dimension(jMenuItem.getPreferredSize().width, jMenuItem.getMaximumSize().height));
        assignCommand(jMenuItem, item);
        menuBar.add(jMenuItem);
    }
}

From source file:com.projity.pm.graphic.frames.GraphicManager.java

public void setToolBarAndMenus(final Container contentPane) {
    JToolBar toolBar;// ww w  .j  av a2  s . c om
    if (Environment.isRibbonUI()) {
        if (Environment.isNeedToRestart()) {
            contentPane.add(new JLabel(Messages.getString("Error.restart")), BorderLayout.CENTER);
            return;
        }

        setRibbon((JRibbonFrame) container, getMenuManager());

        //         JToolBar viewToolBar = getMenuManager().getToolBar(MenuManager.VIEW_TOOL_BAR_WITH_NO_SUB_VIEW_OPTION);
        //         topTabs = new TabbedNavigation();
        //         JComponent tabs = topTabs.createContentPanel(getMenuManager(),viewToolBar,0,JTabbedPane.TOP,true);
        //         tabs.setAlignmentX(0.0f); // so it is left justified
        //
        //
        //          Box top = new Box(BoxLayout.Y_AXIS);
        //          JComponent bottom;
        //         top.add(tabs);
        //         bottom = new TabbedNavigation().createContentPanel(getMenuManager(),viewToolBar,1,JTabbedPane.BOTTOM,false);
        //         contentPane.add(top, BorderLayout.BEFORE_FIRST_LINE);
        //         contentPane.add(bottom,BorderLayout.AFTER_LAST_LINE);
        //         if (Environment.isNewLaf())
        //            contentPane.setBackground(Color.WHITE);

        //         if (Environment.isMac()){
        //            //System.setProperty("apple.laf.useScreenMenuBar","true");
        //            //System.setProperty("com.apple.mrj.application.apple.menu.about.name", Messages.getMetaString("Text.ShortTitle"));
        //            JMenuBar menu = getMenuManager().getMenu(Environment.getStandAlone()?MenuManager.MAC_STANDARD_MENU:MenuManager.SERVER_STANDARD_MENU);
        //            //((JComponent)menu).setBorder(BorderFactory.createEmptyBorder());
        //
        //            ((JFrame)container).setJMenuBar(menu);
        //            projectListMenu = (JMenu) menu.getComponent(5);
        //         }

    } else if (Environment.isNewLook()) {
        if (Environment.isNeedToRestart()) {
            contentPane.add(new JLabel(Messages.getString("Error.restart")), BorderLayout.CENTER);
            return;
        }

        toolBar = getMenuManager().getToolBar(MenuManager.BIG_TOOL_BAR);
        if (!getLafManager().isToolbarOpaque())
            toolBar.setOpaque(false);
        if (!isApplet())
            getMenuManager().setActionVisible(ACTION_FULL_SCREEN, false);

        if (Environment.isExternal()) // external users only see project team
            getMenuManager().setActionVisible(ACTION_TEAM_FILTER, false);

        toolBar.addSeparator(new Dimension(20, 20));
        toolBar.add(new Box.Filler(new Dimension(0, 0), new Dimension(0, 0),
                new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)));
        toolBar.add(((DefaultFrameManager) getFrameManager()).getProjectComboPanel());
        toolBar.add(Box.createRigidArea(new Dimension(20, 20)));
        if (Environment.isNewLaf())
            toolBar.setBackground(Color.WHITE);
        toolBar.setFloatable(false);
        toolBar.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        Box top;
        JComponent bottom;

        top = new Box(BoxLayout.Y_AXIS);
        toolBar.setAlignmentX(0.0f); // so it is left justified
        top.add(toolBar);

        JToolBar viewToolBar = getMenuManager().getToolBar(MenuManager.VIEW_TOOL_BAR_WITH_NO_SUB_VIEW_OPTION);
        topTabs = new TabbedNavigation();
        JComponent tabs = topTabs.createContentPanel(getMenuManager(), viewToolBar, 0, JTabbedPane.TOP, true);
        tabs.setAlignmentX(0.0f); // so it is left justified

        top.add(tabs);
        bottom = new TabbedNavigation().createContentPanel(getMenuManager(), viewToolBar, 1, JTabbedPane.BOTTOM,
                false);
        contentPane.add(top, BorderLayout.BEFORE_FIRST_LINE);
        contentPane.add(bottom, BorderLayout.AFTER_LAST_LINE);
        if (Environment.isNewLaf())
            contentPane.setBackground(Color.WHITE);

        if (Environment.isMac()) {
            //System.setProperty("apple.laf.useScreenMenuBar","true");
            //System.setProperty("com.apple.mrj.application.apple.menu.about.name", Messages.getMetaString("Text.ShortTitle"));
            JMenuBar menu = getMenuManager().getMenu(Environment.getStandAlone() ? MenuManager.MAC_STANDARD_MENU
                    : MenuManager.SERVER_STANDARD_MENU);
            //((JComponent)menu).setBorder(BorderFactory.createEmptyBorder());

            ((JFrame) container).setJMenuBar(menu);
            projectListMenu = (JMenu) menu.getComponent(5);
        }

    } else {

        toolBar = getMenuManager().getToolBar(
                Environment.isMac() ? MenuManager.MAC_STANDARD_TOOL_BAR : MenuManager.STANDARD_TOOL_BAR);
        filterToolBarManager = FilterToolBarManager.create(getMenuManager());
        filterToolBarManager.addButtons(toolBar);
        contentPane.add(toolBar, BorderLayout.BEFORE_FIRST_LINE);
        JToolBar viewToolBar = getMenuManager().getToolBar(MenuManager.VIEW_TOOL_BAR);
        viewToolBar.setOrientation(JToolBar.VERTICAL);
        viewToolBar.setRollover(true);
        contentPane.add(viewToolBar, BorderLayout.WEST);

        JMenuBar menu = getMenuManager().getMenu(Environment.getStandAlone()
                ? (Environment.isMac() ? MenuManager.MAC_STANDARD_MENU : MenuManager.STANDARD_MENU)
                : MenuManager.SERVER_STANDARD_MENU);

        if (!Environment.isMac()) {
            ((JComponent) menu).setBorder(BorderFactory.createEmptyBorder());
            JMenuItem logo = (JMenuItem) menu.getComponent(0);
            logo.setBorder(BorderFactory.createEmptyBorder());
            logo.setMaximumSize(new Dimension(124, 52));
            logo.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }
        ((JFrame) container).setJMenuBar(menu);
        projectListMenu = (JMenu) menu.getComponent(Environment.isMac() ? 5 : 6);
    }

    //accelerators
    addCtrlAccel(KeyEvent.VK_G, ACTION_GOTO, null);
    addCtrlAccel(KeyEvent.VK_L, ACTION_GOTO, null);
    addCtrlAccel(KeyEvent.VK_F, ACTION_FIND, null);
    addCtrlAccel(KeyEvent.VK_Z, ACTION_UNDO, null); //- Sanhita
    addCtrlAccel(KeyEvent.VK_Y, ACTION_REDO, null);
    addCtrlAccel(KeyEvent.VK_N, ACTION_NEW_PROJECT, null);
    addCtrlAccel(KeyEvent.VK_O, ACTION_OPEN_PROJECT, null);
    addCtrlAccel(KeyEvent.VK_S, ACTION_SAVE_PROJECT, null);
    addCtrlAccel(KeyEvent.VK_P, ACTION_PRINT, null); //-Sanhita
    addCtrlAccel(KeyEvent.VK_I, ACTION_INSERT_TASK, null);
    addCtrlAccel(KeyEvent.VK_PERIOD, ACTION_INDENT, null);
    addCtrlAccel(KeyEvent.VK_COMMA, ACTION_OUTDENT, null);
    addCtrlAccel(KeyEvent.VK_PLUS, ACTION_EXPAND, new ExpandAction());
    addCtrlAccel(KeyEvent.VK_ADD, ACTION_EXPAND, new ExpandAction());
    addCtrlAccel(KeyEvent.VK_EQUALS, ACTION_EXPAND, new ExpandAction());
    addCtrlAccel(KeyEvent.VK_MINUS, ACTION_COLLAPSE, new CollapseAction());
    addCtrlAccel(KeyEvent.VK_SUBTRACT, ACTION_COLLAPSE, new CollapseAction());

    // To force a recalculation. This normally shouldn't be needed.
    addCtrlAccel(KeyEvent.VK_R, ACTION_RECALCULATE, new RecalculateAction());
}

From source file:org.datacleaner.windows.ResultWindow.java

/**
 *
 * @param configuration/*from  w ww. j a v  a 2  s .  c o  m*/
 * @param job
 *            either this or result must be available
 * @param result
 *            either this or job must be available
 * @param jobFilename
 * @param windowContext
 * @param userPreferences
 * @param rendererFactory
 */
@Inject
protected ResultWindow(DataCleanerConfiguration configuration, @Nullable AnalysisJob job,
        @Nullable AnalysisResult result, @Nullable @JobFile FileObject jobFilename, WindowContext windowContext,
        UserPreferences userPreferences, RendererFactory rendererFactory) {
    super(windowContext);
    final boolean running = (result == null);

    _resultPanels = new IdentityHashMap<>();
    _configuration = configuration;
    _job = job;
    _jobFilename = jobFilename;
    _userPreferences = userPreferences;
    _rendererFactory = rendererFactory;

    final Ref<AnalysisResult> resultRef = new Ref<AnalysisResult>() {
        @Override
        public AnalysisResult get() {
            return getResult();
        }
    };

    Border buttonBorder = new CompoundBorder(WidgetUtils.BORDER_LIST_ITEM_SUBTLE,
            new EmptyBorder(10, 4, 10, 4));
    _cancelButton = WidgetFactory.createDefaultButton("Cancel job", IconUtils.ACTION_STOP);
    _cancelButton.setHorizontalAlignment(SwingConstants.LEFT);
    _cancelButton.setBorder(buttonBorder);

    _saveResultsPopupButton = WidgetFactory.createDefaultPopupButton("Save results",
            IconUtils.ACTION_SAVE_DARK);
    _saveResultsPopupButton.setHorizontalAlignment(SwingConstants.LEFT);
    _saveResultsPopupButton.setBorder(buttonBorder);
    _saveResultsPopupButton.setMenuPosition(MenuPosition.TOP);
    _saveResultsPopupButton.getMenu().setBorder(new MatteBorder(1, 0, 0, 1, WidgetUtils.BG_COLOR_MEDIUM));

    JMenuItem saveAsFileItem = WidgetFactory.createMenuItem("Save as result file", IconUtils.ACTION_SAVE_DARK);
    saveAsFileItem.addActionListener(new SaveAnalysisResultActionListener(resultRef, _userPreferences));
    saveAsFileItem.setBorder(buttonBorder);
    _saveResultsPopupButton.getMenu().add(saveAsFileItem);

    JMenuItem exportToHtmlItem = WidgetFactory.createMenuItem("Export to HTML", IconUtils.WEBSITE);
    exportToHtmlItem.addActionListener(
            new ExportResultToHtmlActionListener(resultRef, _configuration, _userPreferences));
    exportToHtmlItem.setBorder(buttonBorder);
    _saveResultsPopupButton.getMenu().add(exportToHtmlItem);

    JMenuItem publishToServerItem = WidgetFactory.createMenuItem("Publish to server",
            IconUtils.MENU_DQ_MONITOR);
    publishToServerItem.addActionListener(new PublishResultToMonitorActionListener(getWindowContext(),
            _userPreferences, resultRef, _jobFilename));
    publishToServerItem.setBorder(buttonBorder);
    _saveResultsPopupButton.getMenu().add(publishToServerItem);

    _tabbedPane = new VerticalTabbedPane() {
        private static final long serialVersionUID = 1L;

        @Override
        protected JComponent wrapInCollapsiblePane(final JComponent originalPanel) {
            DCPanel buttonPanel = new DCPanel();
            buttonPanel.setLayout(new VerticalLayout());
            buttonPanel.setBorder(new MatteBorder(1, 0, 0, 0, WidgetUtils.BG_COLOR_MEDIUM));

            buttonPanel.add(_saveResultsPopupButton);
            buttonPanel.add(_cancelButton);

            DCPanel wrappedPanel = new DCPanel();
            wrappedPanel.setLayout(new BorderLayout());
            wrappedPanel.add(originalPanel, BorderLayout.CENTER);
            wrappedPanel.add(buttonPanel, BorderLayout.SOUTH);
            return super.wrapInCollapsiblePane(wrappedPanel);
        }
    };

    final Dimension size = getDefaultWindowSize();
    _windowSizePreference = new WindowSizePreferences(_userPreferences, getClass(), size.width, size.height);
    _progressInformationPanel = new ProgressInformationPanel(running);
    _tabbedPane.addTab("Progress information",
            imageManager.getImageIcon("images/model/progress_information.png", IconUtils.ICON_SIZE_TAB),
            _progressInformationPanel);

    for (Func<ResultWindow, JComponent> pluggableComponent : PLUGGABLE_BANNER_COMPONENTS) {
        JComponent component = pluggableComponent.eval(this);
        if (component != null) {
            if (component instanceof AbstractButton) {
                AbstractButton button = (AbstractButton) component;
                JMenuItem menuItem = WidgetFactory.createMenuItem(button.getText(), button.getIcon());
                for (ActionListener listener : button.getActionListeners()) {
                    menuItem.addActionListener(listener);
                }
                menuItem.setBorder(buttonBorder);
                _saveResultsPopupButton.getMenu().add(menuItem);
            } else if (component instanceof JMenuItem) { // TODO: Not possible. JMenuItem is a subclass of AbstractButton. Reorder or remove?
                JMenuItem menuItem = (JMenuItem) component;
                menuItem.setBorder(buttonBorder);
                _saveResultsPopupButton.getMenu().add(menuItem);
            }
        }
    }

    if (running) {
        // run the job in a swing worker
        _result = null;
        _worker = new AnalysisRunnerSwingWorker(_configuration, _job, this);

        _cancelButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                _worker.cancelIfRunning();
            }
        });
    } else {
        // don't add the progress information, simply render the job asap
        _result = result;
        _worker = null;

        final Map<ComponentJob, AnalyzerResult> map = result.getResultMap();
        for (Entry<ComponentJob, AnalyzerResult> entry : map.entrySet()) {
            final ComponentJob componentJob = entry.getKey();
            final AnalyzerResult analyzerResult = entry.getValue();

            addResult(componentJob, analyzerResult);
        }
        _progressInformationPanel.onSuccess();

        WidgetUtils.invokeSwingAction(new Runnable() {
            @Override
            public void run() {
                if (_tabbedPane.getTabCount() > 1) {
                    // switch to the first available result panel
                    _tabbedPane.setSelectedIndex(1);
                }
            }
        });
    }

    updateButtonVisibility(running);
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.view.ImporterUI.java

/**
 * Sets the defaults of the specified menu item.
 * //  w  w  w .  j  av a2 s  .co  m
 * @param item The menu item.
 */
private void initMenuItem(JMenuItem item) {
    item.setBorder(null);
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java

/**
 * Sets the defaults of the specified menu item.
 * //from  ww w . j av  a 2s  .  c o  m
 * @param item The menu item.
 */
private void initMenuItem(JMenuItem item) {
    item.setBorder(null);
    item.setFont((Font) TreeViewerAgent.getRegistry().lookup("/resources/fonts/Labels"));
}