Java Swing OSX窗口菜单图标对齐 [英] Java Swing OSX Window Menu Icon Alignment

查看:169
本文介绍了Java Swing OSX窗口菜单图标对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java Swing似乎将菜单文本放在MenuItems上的图标(如果存在)之后。请参阅下面的示例。

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

它看起来不太好。

有解决方法吗?

在OSX上,图标适合左边距,文本与所有其他MenuItem对齐。

On OSX the icon fits in the left margin and the text aligns with all other MenuItems.

推荐答案

您可以尝试以下任何一种方法:

You could try either of these approaches:


  • Unicode字符很吸引人,但它们提供的很差以可变间距字体对齐:

  • 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);


  • 更好,实施图标界面,图示此处此处,使用固定大小实现来控制几何体。 CellTest 显示了一种渲染任意unicode字形的方法。

  • 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.

    这篇关于Java Swing OSX窗口菜单图标对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆