0

I can't seem to remember how you create subitems in the menu's. Does anyone know how?

Like this:

Format --> Color(then like a drop down)
*red
*blue
*green

3
Contributors
5
Replies
6
Views
11 Years
Discussion Span
Last Post by server_crash
0

Heres an example of a couple different ones

/*
 * ChoiceTest
 * Demonstrates the Choice Component
 */

import java.awt.*;

public class ChoiceTest {

  public ChoiceTest() {
    //Make the Choices
    Choice c1 = new Choice();
    c1.add("Soup");
    c1.add("Salad");
    Choice c2 = new Choice();
    c2.add("Java");
    c2.add("C++");
    c2.add("HTML");
    c2.add("JavaScript");
    c2.add("COBOL");
    c2.add("FORTRAN");
    Choice c3 = new Choice();
    c3.add("One");
    c3.add("Two");
    c3.add("Three");
    c3.setForeground(Color.red);
    c3.setBackground(Color.black);
    c3.setFont(new Font("Courier", Font.PLAIN, 16));
    Choice c4 = new Choice();
    c4.add("Not Enabled");
    c4.add("Nope");
    c4.setEnabled(false);
    
    //Make the Frame and add the Choices to it
    ComponentTestFrame frame = new ComponentTestFrame("Choice Test");
    frame.add(c1);
    frame.add(c2);
    frame.add(c3);
    frame.add(c4);
    frame.setVisible(true);
  }

  public static void main(String args[]) {
    ChoiceTest ct = new ChoiceTest();
  }

}
0

I think you want something with swings since you mentioned JMenu.
here's a simple example:

JMenu menu = new JMenu("Color");

JMenuItem blueM = new JMenuItem("blue");

// and do this for the others and once done add them to your menu
//ex:

menu.add(blueM); // and so on hope this helps


good luck,
Mel

0

Yes, I know how to create the Menu's and the Menu items, but how do you have menu items with subcategories...Look at this screenshot to see what I'm saying.

Attachments whatiwant.jpeg 195.43 KB
0

Ho,

Well it depends you can create one of these and add them to your drop down menu object:

JRadioButtonMenuItem
JCheckBoxMenuItem

I'm sure there are others but these are the only two that i ever used. create these and add them to your MenuItem objects.
I don't know if that's what you wanted to hear, but that's all i got.:cry:

Mel

0

Thank you all for the help. I guess I was unclear on what I wanted. I figured out how to do this though. What you do, is simply add a JMenu, to a JMenu, and that makes it to were you can have subcategories.

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.