Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Not setting colors in JMenu submenu like it should.

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Not setting colors in JMenu submenu like it should.

    It seems to do this every single solitary time so I think I can make a shorter version of it that will show what's going on.


     
    import javax.swing.JMenuItem;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.awt.Color;
     
    public class BustedMenuExample 
    {
     
    public BustedMenuExample()
    {
     
    JFrame theFrame = new JFrame("Why isn't this working properly? :(  ");
     
    JPanel contentPane = new JPanel();
     
    theFrame.setContentPane(contentPane);
     
    theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    theFrame.setVisible(true);
     
    JMenuBar jmb = new JMenuBar();
    jmb.setBackground(Color.BLUE);
     
    theFrame.setJMenuBar(jmb);
     
    JMenu menu = new JMenu("Menu");
    menu.setBackground(Color.BLUE);
    menu.setForeground(Color.GREEN);
     
    jmb.add(menu);
     
    JMenu subMenu = new JMenu("Sub-Menu");
     
    menu.add(subMenu);
     
    subMenu.setBackground(Color.BLUE);
    subMenu.setForeground(Color.GREEN);
     
    JMenuItem menuItem = new JMenuItem("Menu Item");
     
    subMenu.add(menuItem);
     
    menuItem.setBackground(Color.BLUE);
    menuItem.setForeground(Color.GREEN);
     
    JMenuItem menuItem2 = new JMenuItem("Menu Item 2");
     
    subMenu.add(menuItem2);
     
    menuItem2.setBackground(Color.BLUE);
     
    menuItem2.setForeground(Color.GREEN);
     
     
     
     
     
     
     
    }
     
    public static void main(String[] args)
    {
    new BustedMenuExample();
     
     
     
    }
     
    }

    I'm thinking that all the backgrounds and stuff will be fine except that subMenu will still have a cyan background and black foreground. Why is that happening?

    I think I figured it out. You use setOpaque(true); Yes, that worked. That was just a hunch though.

    What does opaque mean anyway? I thought it meant see-through or something.

    Another thing I was slightly wondering is how do you set the selectionColor? I mean, when it's selected, it appears to be a dark gray by default. How would you make it, say, a dark red instead or something?
    Last edited by javapenguin; June 21st, 2012 at 10:16 PM.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,669
    Thanks
    25
    Thanked 327 Times in 304 Posts

    Default Re: Not setting colors in JMenu submenu like it should.

    Is this what you are talking about: How to change color of JMenuItem when mouse is over it
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    javapenguin (June 22nd, 2012)

  4. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Not setting colors in JMenu submenu like it should.

    Thanks. However, it appears it's a Model-T style thing, not that I have to choose black, but that I can't have one JMenu with a Red selection and another, in the same program, with a Green selection. At least that's what it appears from the UIManager.

Similar Threads

  1. Liitle help with Jmenu
    By cute in forum What's Wrong With My Code?
    Replies: 11
    Last Post: November 13th, 2011, 07:09 PM
  2. setVerifyInputWhenFocusTarget problem with JMenu
    By Jack_Maloney in forum AWT / Java Swing
    Replies: 0
    Last Post: March 25th, 2011, 10:44 AM
  3. How to create submenu?
    By SHENGTON in forum Java ME (Mobile Edition)
    Replies: 3
    Last Post: January 14th, 2011, 11:55 PM
  4. jmenu&jframe problem
    By beni.vd in forum AWT / Java Swing
    Replies: 1
    Last Post: January 2nd, 2011, 11:11 AM
  5. JMenu and JComboBox
    By javapenguin in forum AWT / Java Swing
    Replies: 1
    Last Post: July 3rd, 2010, 05:00 PM