JMenuBar 错误(重复和重叠)

Error with JMenuBar (duplicates and overlaps)

我正在制作一个 window,其中包含 1 个 JFrame 并且在 JFrame 内部包含一个 JMenuBar -> 3 JMenu -> 每个 JMenu 中的几个 JMenuItem ...在 JFrame 内部我还有几个按钮和一个JLabel.

发生在我​​身上的问题是我将 JMenu 放在点击的那一刻。

这将是我在 JMenu 中的代码(在其他 Jmenu 中仅改变打开的 pdf)

    try {
    Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + "C:/Users/Abad Hermida/Documents/NetBeansProjects/MRP/Manual/Manual.pdf");
} catch (IOException e) {
    JOptionPane.showMessageDialog(rootPane, "Error al Abrir el Archivo", "ERROR", JOptionPane.ERROR_MESSAGE);
}

代码有效...我在按钮中的代码(在其他按钮中仅在打开时有所不同)

open.setVisible(true);
open.setTitle("Administrator");
this.setVisible(false);

这是 SOURCE

的 class
public Users() {
initComponents();
setTitle("Users");
setIconImage(new        ImageIcon(getClass().getResource("../icons/32x32/users.png")).getImage());
}

图像加深理解

在左侧,您会看到 window 应该如何显示,在导航 JMenu 后在右侧看到,在第二张图片中,只需突出显示 WINDOW 的组件导航器有问题。

在这张图片中,左侧显示的是应有的样子,右侧显示的是分解后的样子:

在第二张图片中,只需突出显示问题中 WINDOW 的组件导航器:

This would be the code I have in JMenu (in the other Jmenu only varies only the pdf that opens)

如果您尝试显示 PDF 文件,那么您应该使用 Desktop class。这是一个独立于平台的解决方案。

阅读有关 How to Integrating With the Desktop Class 的 Swing 教程部分,了解更多信息和工作示例。