Java Swing OSX Window Menu Icon Alignment

前端 未结 2 1260
攒了一身酷
攒了一身酷 2020-12-12 06:37

Java Swing seems to place the \'Menu Text\' after the icon (if present) on MenuItems. See example below.

\"Windo

2条回答
  •  忘掉有多难
    2020-12-12 07:17

    You could try either of these approaches:

    • Unicode characters are appealing, but they offer poor alignment in a variable pitch font:

      JMenuBar menuBar = new JMenuBar();
      JMenu windowMenu = new JMenu("Window");
      windowMenu.add(new JMenuItem("♦ Item"));
      windowMenu.add(new JMenuItem("✓ Item"));
      windowMenu.add(new JMenuItem("• Item"));
      menuBar.add(windowMenu);
      frame.setJMenuBar(menuBar);
      
    • Better, implement the Icon interface, illustrated here and here, using a fixed-size implementation to control geometry. CellTest shows one approach to rendering an arbitrary unicode glyph.

提交回复
热议问题