java菜单项分隔符在GNOME环境下不可见(使用“GTK”LAF时)
我有一个Java桌面应用程序(文档编辑器),最近我在其中添加了一个菜单栏,菜单中又有菜单项。问题是——在我的GNOME桌面环境(Ubuntu)中,菜单项分隔符根本不可见。如果我切换应用程序L&;F默认为Java(metal)LaF或在Ubuntu上切换桌面环境KDE环境,但在GNOME环境下,菜单项分隔符永远不可见。此外,我正在设置应用程序L&;F到“GTK”。如果我强迫L&;F到“motif”,文件分隔符可以清晰地看到
以前有没有人在Ubuntu GNOME环境中遇到过这种问题?我附上下面的代码-这是直截了当的,不认为这里有任何问题
import java.awt.EventQueue;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class Test {
static JFrame frame = null;
static JMenuBar menubar = null;
static JMenu filemenu = null;
public static void main (String[] args) throws InterruptedException,
InvocationTargetException {
EventQueue.invokeAndWait(new Runnable () {
@Override
public void run() {
createAndShowGUI ();
}
});
}
private static void createAndShowGUI () {
/* Set LAF to GTK LAF */
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
/* Create frame */
frame = new JFrame ();
frame.setLocation(50, 50);
frame.setSize(400, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
/* Add menu bar */
addMenuBar ();
}
private static void addMenuBar () {
/* Create menu bar and then file menu*/
menubar = new JMenuBar ();
filemenu = new JMenu ("File");
/* Add three menu items to the file menu */
JMenuItem newItem = new JMenuItem ("New ");
JMenuItem openItem = new JMenuItem ("Open ");
JMenuItem exitItem = new JMenuItem ("Exit ");
/* Add the menu items to the file menu. Also separate the last item
* from the first two using a menu item separator */
filemenu.add(newItem);
filemenu.add(openItem);
filemenu.addSeparator();
filemenu.add(exitItem);
/* Add the file menu to the menu bar */
menubar.add(filemenu);
/* Add menu bar to frame */
frame.setJMenuBar(menubar);
}
}
所以问题是——在使用“GTK”L&;在GNOME环境中,使菜单项分隔符再次可见
[编辑:这篇文章现在已经被编辑以反映sscce。如果你想看到Java LAF的效果,请在createAndShowGUI()中注释掉LAF硬编码为GTK LAF的行。Java LAF的问题消失了,但在使用GTK LAF时仍然存在]
共 (0) 个答案