wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JMenuBar in an Applet : Good vs Bad Code Practice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JMenuBar in an Applet : Good vs Bad Code Practice?" Watch "JMenuBar in an Applet : Good vs Bad Code Practice?" New topic
Author

JMenuBar in an Applet : Good vs Bad Code Practice?

achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Hi, after a day of experimenting, following code is the only way I can get a JMenuBar in an applet, which gets invoked by html. I can further refine it by putting the menu bar in a JTextArea in borderlayout north, but the question is whether there is a better way, and whether this code is the normal way to put a JMenuBar in an applet:
Is there a better way?


humanum errare est.
Jason Steele
Ranch Hand

Joined: Apr 25, 2003
Posts: 100
What about:
import javax.swing.*;
import java.awt.*;
public class Applet extends JApplet {

/** Initialization method that will be called after the applet is loaded
* into the browser.
*/
public void init() {
JFrame frame = new JFrame("TITLE");
JMenuBar jmb = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem menuItem = new JMenuItem("MenuItem");
menu.add(menuItem);
jmb.add(menu);
Container c = frame.getContentPane();
c.add(jmb);
...add more content here...
frame.pack();
frame.show();

}

}

This would put the menu in a frame where it should be. Does this help?


An egg is a chicken's house!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JMenuBar in an Applet : Good vs Bad Code Practice?
 
Similar Threads
JCheckboxMenuItem won't change selection color
Is this a bug..?
mnemonics are not getting focus for the menubar
Creating one class from another
Applet -Servlet connection in JNLP