java jframe菜单栏显示设置
时间: 2023-09-10 17:07:15 浏览: 72
您可以使用JMenuBar和JMenu类来创建JFrame菜单栏。以下是一个示例代码:
```
import javax.swing.*;
public class MyFrame extends JFrame {
JMenuBar menuBar;
JMenu fileMenu, editMenu, helpMenu;
public MyFrame() {
// Set the title of the JFrame
setTitle("My Java App");
// Create a menu bar
menuBar = new JMenuBar();
// Create menus
fileMenu = new JMenu("File");
editMenu = new JMenu("Edit");
helpMenu = new JMenu("Help");
// Add menus to menu bar
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(helpMenu);
// Set menu bar for this JFrame
setJMenuBar(menuBar);
// Set other properties of JFrame
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new MyFrame();
}
}
```
这个示例代码会创建一个有File、Edit和Help三个菜单的JFrame。您可以根据自己的需要进行修改和扩展。