gpt4 book ai didi

java - 看不到菜单栏

转载 作者:行者123 更新时间:2023-12-02 06:17:38 25 4
gpt4 key购买 nike

我编写的代码不显示菜单栏,知道我应该做什么吗?

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//What happens on close.
this.setSize(1100, 750);//Initial size of the frame.

menuBar = new MenuBar();

east = new EastPanel();
central = new CentralPanel();
south = new SouthPanel();

//Add the menu bar to the frame.
this.setJMenuBar(menuBar.getComposition());

//Frame's other components.
this.add(central.getCentralPanel());
//this.add(msBoard.getMessagesBoard(), BorderLayout.SOUTH);
this.add(east.getEastPanel(), BorderLayout.EAST);
this.add(south.getSouthPanel(), BorderLayout.SOUTH);
//this.add(menuBar);
//Load the card images.
//cards = new CardImages();
//cards.loadCards();

//Initialize cardsPerPlayer list.
//cardsPerPlayer = new ArrayList<ImagePanel>();

this.setVisible(true);

其中 getComposition 是

public JMenuBar getComposition(){
return this.Composition;
}

并且Composition是私有(private)的JMenuBar

最佳答案

添加 MenuBar 还不够。您应该将其附加到当前的 JFrame 对象。
还要确保您向其中添加了一些菜单项。

示例:

frame.setJMenuBar(theJMenuBar);

关于java - 看不到菜单栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21307628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com