Example usage for javax.swing JMenuItem getMaximumSize

List of usage examples for javax.swing JMenuItem getMaximumSize

Introduction

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

Prototype

@Transient
public Dimension getMaximumSize() 

Source Link

Document

If the maximum size has been set to a non-null value just returns it.

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//  ww w  .j a va 2s  .c om
            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);
    }
}