문제는 간단 해 보이지만 해결할 수없는 것 같습니다.Java - JMenuBar가 유리 창을 사용할 때 숨김
내 프레임 (또한 ContentPane)에 GlassPane을 사용하고 있습니다. 그래서 프레임에 JMenuBar를 추가하면 나타나지 않습니다. 다른 시간에 GlassPane을 사용할 경우 모든 것이 완벽하게 작동합니다. 몇 가지 조사를했는데 JMenuBar가 RootPane에 표시되고 GlassPane이 어떻게 든 그것을 숨기고 있다고 생각합니다.
glassPane을 사용하는 동안 JMenuBar를 가져올 수있는 방법이 있는지 알아야합니까?
감사
UPDATE : I (false)를 glassPane.setOpaque를 설정하고
UPDATE : 코드의
실제 라인이 훨씬 더하지만 문제는 여기에 상대적 것들입니다 .
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();
}
}
문제를 재현하는 코드를 제공하십시오. –
@SergiyMedvynskyy 일부 코드 줄과 스크린 샷을 추가했습니다. – Abbas
@ AbbasA.Ali * "some lines of code"*는 실행 가능한 예제를 작성하지 않습니다. 문제를 재현 할 수 없다면 문제를 해결할 수 없습니다. 다른 모든 것은 일을 추측합니다. 문제를 나타내는 [실행 가능한 예제] (https://stackoverflow.com/help/mcve)를 제공하십시오. 이렇게하면 혼란이 적고 응답이 좋아집니다. – MadProgrammer