I can't remember how to get subcategories with JMenu's. If anyone knows how, please let me know. I'll post a screenshot so you know exactly what I'm talking about.
Printable View
I can't remember how to get subcategories with JMenu's. If anyone knows how, please let me know. I'll post a screenshot so you know exactly what I'm talking about.
Never mind, I figured it out.
Why don't you post the solution so maybe someone else could find it in the future :)Quote:
Originally Posted by System_Error
All you do, is add a JMenu, to a JMenu!
I'll demonstrate below:
Code:JMenuBar menuBar = new JMenuBar();
//Normal menu with no submenu's
JMenu fileMenu = new JMenu("File");
fileMenu.add(new JMenuItem("Exit");
//this will have submenu's
JMenu format = new JMenu("Format");
format.add(new JMenuItem("Font"));
/* start making the submenu, by creating
* a menu, and adding items to it...Once
* finished, add the color menu to the format
* menu
*/
JMenu color = new JMenu("Color");
color.add(new JMenuItem("Red"));
color.add(new JMenuItem("Blue"));
//add the menu to the other menu
format.add(color);
menuBar.add(fileMenu);
menuBar.add(format);
Yes quite simple.
Code:import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class X{
public static void main(String[] args){
JFrame jf = new JFrame("JMenu Example");
Container c = jf.getContentPane();
JMenuBar jmb = new JMenuBar();
JMenu jm = new JMenu("File");
JMenu sendto = new JMenu("Send To");
JMenuItem print = new JMenuItem("Print");
JMenuItem exit = new JMenuItem("Exit");
jf.setJMenuBar(jmb);
jmb.add(jm);
jm.add(sendto);
jm.add(print);
jm.add(exit);
// add sub menu
sendto.add(new JMenuItem("3 1/2 Floppy(A)"));
sendto.add(new JMenuItem("DeskTop"));
sendto.add(new JMenuItem("Web Publishing Wizard"));
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});
jf.setSize(400,300);
jf.setVisible(true);
}
}