JMenu as a submenu?

Hi all

I have a JMenu which is a submenu of another

What my problem is is I cannot change the background color of the submenu

here is the code

menuBar =new JMenuBar();

menuBar.setBackground(Color.blue);

menu =new JMenu("Menu");

menu.setBackground(Color.blue);

submenu =new JMenuItem("submenu");

submenu.setBackground(Color.blue);

item1 =new JMenuItem("item1");

item1.setBackground(Color.blue);

submenu.add(item1);

menu.add(submenu);

menuBar.add(menu);

Although I change their background color to blue, the submenu is still grey, which I can't construe.

what is wrong with this simple code?

thanks

[917 byte] By [voywodaa] at [2007-10-3 2:12:09]
# 1
>>menuBar = new JMenuBar();>>menuBar.setBackground(Color.blue);These two lines of code are correct. Can you show just a little bit more of your code?
jSpencea at 2007-7-14 19:11:06 > top of Java-index,Java Essentials,New To Java...
# 2

Here is the whole code

import javax.swing.*;

import java.awt.*;

public class Deneme extends JFrame {

JMenuBar menuBar;

JMenu menu, submenu;

JMenuItem item1, item2;

public Deneme() {

menuBar = new JMenuBar();

menuBar.setBackground(Color.blue);

menu = new JMenu("Menu");

menu.setBackground(Color.blue);

submenu = new JMenu("submenu");

submenu.setBackground(Color.blue);

item1 = new JMenuItem("item1");

item1.setBackground(Color.blue);

submenu.add(item1);

menu.add(submenu);

menuBar.add(menu);

setJMenuBar(menuBar);

setVisible(true);

setSize(200, 100);

}

public static void main(String[]args){

new Deneme();

}

}

thanks

Message was edited by:

voywoda

voywodaa at 2007-7-14 19:11:06 > top of Java-index,Java Essentials,New To Java...
# 3

Your code works, to a degree. If you change the size of the window you will see a blue menubar. I suggest that you look at the following link and take a look at the main methods used in those examples, and implement your program accordingly.

http://java.sun.com/docs/books/tutorial/uiswing/index.html

jSpencea at 2007-7-14 19:11:06 > top of Java-index,Java Essentials,New To Java...
# 4

> If you change the size of the window you will see a blue menubar.

It seems I will not :)

I think I couldn't explain my problem, ( it must be because of my bad english ). My problem is not with the menubar or the menu, my problem is with the submenu that I stated in the whole code above.

here is the image of my problem

http://img264.imageshack.us/my.php?image=submenuhk1.jpg

What I want is to change the color of the "submenu" part in the image to be blue, but setBackground doesn't work

thanks

voywodaa at 2007-7-14 19:11:06 > top of Java-index,Java Essentials,New To Java...
# 5
.......the're blue on my machine.
jSpencea at 2007-7-14 19:11:06 > top of Java-index,Java Essentials,New To Java...
# 6
:) then, there may be version differences or something, but lastly I had better try Swing forum, maybe the answer is around there :Pthanks for your interest
voywodaa at 2007-7-14 19:11:06 > top of Java-index,Java Essentials,New To Java...
# 7
............that's a good idea, wish I could have been more helpful.
jSpencea at 2007-7-14 19:11:06 > top of Java-index,Java Essentials,New To Java...