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?