• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Is this a bug..?

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

I downloded a java file from sun's swing tutorial. (http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/MenuLookDemo.java)

I edited the code and added the following two lines.

menu.setBackground(Color.RED);// This is the first line that I added
submenu.setBackground(Color.GREEN);// This is the seccond line that I added

It worked as expected when I tested with java version "1.4.2_04"
But, unfortunately, it is not working with java version "1.5.0"
The background color is set properly when I use java version other than "1.5.0"
But when I use java version "1.5.0", The back ground is still the default background color.

Am I doing anything wrong..?
Or is this a bug..?
I tested in windows 98 and XP. Both produced the same result.
So I guess the problem is with jre.
Here is the code



Thanks
Shahabas E Shabeer
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The evaluation in this bug report points toward the change from j2se 1.4 to 1.5

Method setBackground() does not work when JMenu is a submenu

which is that JMenu is non–opaque by default in j2se 1.5 to accomodate the Ocean LookAndFeel. You can try this before you instantiate any menus

As an aside, this is why it is recommended that we call setOpaque(true) on any JComponent that is used as an argument in the JFrame setContentPane method.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed, at this point it's a good rule of thumb to explicitly set components opaque (or not opaque) because what they instantiate to is not always predictable. As the above poster hinted at, this can be a problem with JPanel's as well, especially when used for a content pane.
 
shahabas shabeer
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes .. you are right..
I think the transparancy of the component depends on the look and feel used.
The code that I posted worked fine when I set native look and feel than the default swing look and feel.
I do now believe that it is always better to explicitly set the transparancy of the component.
Thanks a lot for all your help
cheers
Shahabas E Shabeer
 
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic