javax.swing.JMenuBar.setLayout()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(96)

本文整理了Java中javax.swing.JMenuBar.setLayout()方法的一些代码示例,展示了JMenuBar.setLayout()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JMenuBar.setLayout()方法的具体详情如下:
包路径:javax.swing.JMenuBar
类名称:JMenuBar
方法名:setLayout

JMenuBar.setLayout介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

// sanity check: does grid respect component alignment?
// manager does, but menu internal layout doesn't
JComponent content = new JPanel(new GridLayout(3, 3));
for (int i = 0; i < 9; i++) {
  if (i % 2 == 0) {
    JMenu menu = new JMenu("menu: " + i);
    menu.setBorderPainted(true);
    menu.setBorder(BorderFactory.createLineBorder(Color.GREEN));
    menu.setHorizontalAlignment(JMenu.CENTER);
    content.add(menu);
  } else {
    JLabel menu = new JLabel("label: " + i);
    menu.setBorder(BorderFactory.createLineBorder(Color.GREEN));
    menu.setHorizontalAlignment(JMenu.CENTER);
    content.add(menu);
  }
}
JXFrame frame = wrapInFrame(content, "menuBar with GridLayout");
JMenuBar bar = getMenuBar(frame);
// not surprisingly (after sanity check), 
// horizontal align isn't respected in the menubar as well
bar.setLayout(new GridLayout(1, 0));
JMenu menu = new JMenu("some dummy");
menu.setBorderPainted(true);
menu.setBorder(BorderFactory.createLineBorder(Color.GREEN));
menu.setHorizontalAlignment(JMenu.CENTER);
bar.add(menu);
bar.add(new JMenu("other"));
show(frame, 500, 500);

代码示例来源:origin: freeplane/freeplane

private void insertSubmenus(final JToolBar iconToolBar) {
  final JMenuBar iconMenuBar = new JMenuBar() {
    private static final long serialVersionUID = 1L;
    @Override
    public Dimension getMaximumSize() {
      final Dimension preferredSize = getPreferredSize();
      return new Dimension(Short.MAX_VALUE, preferredSize.height);
    }
  };
  iconMenuBar.setAlignmentX(JComponent.CENTER_ALIGNMENT);
  iconMenuBar.setLayout(new GridLayout(0, 1));
  for (final IconGroup iconGroup : STORE.getGroups()) {
    iconMenuBar.add(getSubmenu(iconGroup));
  }
  iconToolBar.add(iconMenuBar);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf

public void propertyChange(PropertyChangeEvent e)
  {
    String name= e.getPropertyName();
    if (name.equals("componentOrientation")
      && (menuBar.getLayout() instanceof UIResource))
    {
      if (TonicUtils.isLeftToRight(menuBar))
      {
        menuBar.setLayout(
          new DefaultMenuLayout(menuBar, BoxLayout.X_AXIS));
      }
      else
      {
        menuBar.setLayout(new RightToLeftMenuLayout());
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

bar.setLayout(new MigLayout());

代码示例来源:origin: stackoverflow.com

JMenuBar createCustomMenu() {
  final CardLayout layout = new CardLayout();
  final JMenuBar menu = new JMenuBar();
  menu.setLayout(layout);

  // Here you should create the normal, wide menu
  JComponent normalMenu = createNormalMenu();
  // Here you create the compressed, one button version
  JComponent compressedMenu = createCompressedMenu();

  menu.add(normalMenu, "normal");
  menu.add(compressedMenu, "compressed");

  menu.addComponentListener(new ComponentAdapter() {
    public void componentResized(ComponentEvent e) {
      if (menu.getPreferredSize().getWidth() > menu.getWidth()) {
        layout.show(menu, "compressed");
      } else {
        layout.show(menu, "normal");
      }
    }
  });

  return menu;
}

代码示例来源:origin: org.verapdf.apps/gui

menuBar.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
setJMenuBar(menuBar);

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf

/**	Installs the default settings for the associated menu bar */
protected void installDefaults()
{
  if (menuBar.getLayout() == null
    || menuBar.getLayout() instanceof UIResource)
  {
    if (TonicUtils.isLeftToRight(menuBar))
    {
      menuBar.setLayout(new DefaultMenuLayout(menuBar, BoxLayout.X_AXIS));
    }
    else
    {
      menuBar.setLayout(new RightToLeftMenuLayout());
    }
  }
  
  menuBar.setOpaque(true);
  LookAndFeel.installBorder(menuBar, "MenuBar.border");
  LookAndFeel.installColorsAndFont(menuBar, "MenuBar.background", "MenuBar.foreground", "MenuBar.font");
}

代码示例来源:origin: edu.toronto.cs.savant/savant-core

toolbar.setLayout(new BoxLayout(toolbar,BoxLayout.X_AXIS));
c.add(toolbar, BorderLayout.NORTH);

代码示例来源:origin: Audiveris/audiveris

outerBar.setLayout(new GridLayout(1, 0));
outerBar.add(innerBar);
outerBar.add(gauges);

相关文章