删除默认小程序菜单
我正在开发 JApplet,但我想要一个自定义菜单。当我插入此菜单时,我仍然会看到小程序菜单并位于我自己的菜单下方。
package multiformat;
import ui.*;
import javax.swing.*;
import java.awt.*;
public class CalculatorMVC extends JApplet{
Command command; // het model
JTextField input;
public void init()
{
resize(250,200);
// Maak het model
Calculator calc=new Calculator();
// Maak de controller en geef hem het model
command = new Command(calc);
input = new JTextField();
input.setHorizontalAlignment(input.RIGHT);
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Menu");
menuBar.add(menu);
JMenu help = new JMenu("Help");
menuBar.add(help);
// Create a menu item
JMenuItem item = new JMenuItem("Label");
//item.addActionListener(actionListener);
menu.add(item);
// this.setJMenuBar(menuBar);
getContentPane().add(input, BorderLayout.NORTH);
getContentPane().add(command,BorderLayout.SOUTH);
}
}
在这种情况下,两个菜单都会显示。我自己的和小程序默认的。如何从小程序中删除默认设置?
I'm working on a JApplet, but I want a custom menu. When I insert this menu, I still get the applet menu and below my own menu.
package multiformat;
import ui.*;
import javax.swing.*;
import java.awt.*;
public class CalculatorMVC extends JApplet{
Command command; // het model
JTextField input;
public void init()
{
resize(250,200);
// Maak het model
Calculator calc=new Calculator();
// Maak de controller en geef hem het model
command = new Command(calc);
input = new JTextField();
input.setHorizontalAlignment(input.RIGHT);
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Menu");
menuBar.add(menu);
JMenu help = new JMenu("Help");
menuBar.add(help);
// Create a menu item
JMenuItem item = new JMenuItem("Label");
//item.addActionListener(actionListener);
menu.add(item);
// this.setJMenuBar(menuBar);
getContentPane().add(input, BorderLayout.NORTH);
getContentPane().add(command,BorderLayout.SOUTH);
}
}
In this case both menu's show up. My own and the default from applet. How can I remove the default from applet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除小程序的小程序查看器菜单栏的小技巧:
init()
时,小程序仍然嵌入在页面中,并且没有可以从中删除菜单栏的小程序查看器框架.)编译&展示
A small hack to remove the applet viewer menu bar for applets:
init()
is called, the applet is still embedded in the page and there is no applet viewer frame from which to remove the menu bar.)To compile & show
小程序没有默认菜单栏。您是指
appletviewer
实用程序的菜单栏吗?没有办法删除它,因为框架不是由小程序创建的;同样,您无法从最终托管小程序的 Web 浏览器中删除菜单栏。编辑我错了,请参阅安德鲁的回答。
Applets don't have a default menubar. Do you mean the menubar of the
appletviewer
utility? There is no way to remove it because the frame is not created by the applet; in the same way you cannot remove the menubar from a web browser that would eventually host the applet.Edit I was wrong, see Andrew's answer.