该问题看起来很简单,但我似乎无法解决它。Java - 使用玻璃面板隐藏JMenuBar
我在我的框架(也是ContentPane)中使用GlassPane。所以当我将JMenuBar添加到框架中时,它不会显示出来。如果/当我在其他时间使用GlassPane时,一切都可以正常工作。我做了一些研究,我的理解是JMenuBar显示在RootPane上,我相信GlassPane以某种方式隐藏它。
我需要知道在使用glassPane时是否有任何方法获得JMenuBar?
感谢
更新: 我设置glassPane.setOpaque(假)
UPDATE:
的代码中实际的线条更加但是这里是相对于问题的那些。 (mainPanel中和notificationPanel从JPanel的扩展自构造类)和
public class Demo extends JFrame {
/////////////////////////////////////////////////////////////////////////
// JMenuBar
private final JMenuBar mainMenuBar;
private final JMenu fileMenu;
private final JMenuItem exitFileMenu;
/////////////////////////////////////////////////////////////////////////
// CONTENT PANE & COMPONENTS
private final JPanel contentPanel;
private final JPanel buttonPanel;
private final JButton button1;
/////////////////////////////////////////////////////////////////////////
// GLASSPANE AND COMPONENTS
private final JPanel glassPanel;
private final JPanel buttonPanel2;
private final JButton button2;
public Demo() {
super();
this.mainMenuBar = new JMenuBar();
this.fileMenu = new JMenu("File");
this.exitFileMenu = new JMenuItem("EXIT");
this.contentPanel = new JPanel(new BorderLayout());
this.buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
this.button1 = new JButton("Button 1");
this.glassPanel = new JPanel(new BorderLayout());
this.buttonPanel2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
this.button2 = new JButton("Button 2");
}
public void initGUI() {
this.fileMenu.add(this.exitFileMenu);
this.mainMenuBar.add(this.fileMenu);
this.buttonPanel.add(this.button1);
this.contentPanel.add(this.buttonPanel, BorderLayout.NORTH);
this.buttonPanel2.add(this.button2);
this.glassPanel.add(this.buttonPanel2, BorderLayout.NORTH);
super.setContentPane(this.contentPanel);
super.setGlassPane(this.glassPanel);
this.glassPanel.setOpaque(false);
this.glassPanel.setVisible(true);
super.setExtendedState(JFrame.MAXIMIZED_BOTH);
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
super.setJMenuBar(mainMenuBar);
super.setVisible(true);
}
public static void main(String[] args) {
Demo obj = new Demo();
obj.initGUI();
}
}
请提供任何代码来重现您的问题 – 2014-11-23 22:31:04
@SergiyMedvynskyy我添加了一些代码行和屏幕快照。 – Abbas 2014-11-23 22:54:50
@ AbbasA.Ali *“一些代码行”*不能生成可运行的示例。如果我们无法复制您的问题,我们不太可能解决它。一切都是猜测工作。考虑提供一个[可运行的示例](https://stackoverflow.com/help/mcve),它可以证明你的问题。这会减少混淆和更好的反应 – MadProgrammer 2014-11-23 23:03:29