• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JMenu text color

 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm calling setForeground() in order to change the color of the title displayed by the JMenu (I want to change the color of the JMenu's title, but not the colors of the JMenuItem's titles that are contained in the JMenu). Anyway, setting foreground color has no effect on the color of the text. Anybody know how to do this?
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works fine for me. I suggest you post a SSCCE that demonstrates your problem.

By the way, are you planning to tell us about the TugWhumper and HogSplat here too?
http://forum.java.sun.com/thread.jspa?threadID=5299145
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I discovered something interesting by an accidental type-O.

Here's the code that doesn't work:



In creating this simplified example, I accidentally typed:



instead of typing:



This actually made the title of the Menu green. Unfortunately, I need to set the menu titles independently (instead of having all menu titles be the same color).
[ May 25, 2008: Message edited by: Wally Flint ]
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh man... it's getting late. Type-O in the text above too:

when i do this:



the color doesn't change. but when i do this:



then the text of the JMenu is green. As I said, I need to control the text color of each JMenu independently.

Thanks for any advice.
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And I'm having another problem with JMenuItem. If I listen for mouseReleased, the behavior seems unpredictable. On a MacBook Pro, if I click the JMenu to open it up, then release the mouse, then move the mouse down until it is over the JMenuItem, then click the mouse, the listener that is listening to the JMenuItem gets a mouseReleased. But if I press and hold the mouse on the JMenu, then keep holding the mouse down until I am over the JMenuItem, then release the mouse, I don't get a mouseReleased...

man this swing stuff is enough to drive you to distraction.

 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yes, and one more thing!!

When I select the JMenuItem, I want to keep the JMenu that contains it from collapsing until I have instantiated a JOptionPane (like an "ok" message), and then after the user clicks "ok" in the dialog box, I'll let the JMenu collapse. Can't figure out how to do that either. This is one of those days where I've spent so many hours trying to do the simplest things that I can't think anymore. Pardon me if I'm asking stupid questions.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wally,

If you need to update your posts, could you please use the edit () button next time? Three posts in 7 minutem is not really necessary without any posts in between.
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see... didn't notice the edit button. Will use it next time.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Wally Flint:
Oh yes, and one more thing!!

When I select the JMenuItem, I want to keep the JMenu that contains it from collapsing until I have instantiated a JOptionPane (like an "ok" message), and then after the user clicks "ok" in the dialog box, I'll let the JMenu collapse. Can't figure out how to do that either. This is one of those days where I've spent so many hours trying to do the simplest things that I can't think anymore. Pardon me if I'm asking stupid questions.



This isn't really that simple. You are trying to change default menu behavior. You'll need to dig deep into the underlying API and probably intercept mouse and focus events to over rule the default. Probably be more work than what its worth.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Wally Flint:
And I'm having another problem with JMenuItem. If I listen for mouseReleased, the behavior seems unpredictable. On a MacBook Pro, if I click the JMenu to open it up, then release the mouse, then move the mouse down until it is over the JMenuItem, then click the mouse, the listener that is listening to the JMenuItem gets a mouseReleased. But if I press and hold the mouse on the JMenu, then keep holding the mouse down until I am over the JMenuItem, then release the mouse, I don't get a mouseReleased...

man this swing stuff is enough to drive you to distraction.



Well, to be fair its the AWT stuff that is getting you here. Also, it seems you are trying very odd things. What exactly is the ultimate goal here?
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the text color issues is related to my running it on the MacBook Pro. I'm thinking the easiest way to solve this issues to force a certain look and feel that honors the setForeground method. So the only other issues is how to freeze the JMenu in its popped up state whenever one of its menu items are selected. I did that with a JButton by overriding the fireActionPerformed
method. I popped up my "OK" dialog box with its little blurb of information. This blocks the thread until the user clicks the dialog's OK button. Once the button has been clicked, I call super.actionPerformed(actionEvent) to make the button do its thing. I need a similar effect for a JMenuItem... the only thing is I guess I can't do it by overriding a JMenuItem method, because it is the JMenu that is collapsing, not the JMenuItem. I didn't realize this until tonight, so I guess tomorrow I'll try to look at the JMenu api and see if there's a similar trick to use there.
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was right. After inserting the line:



at the beginning of the code posted above, the menu title text does indeed turn green.

Thanks for the help.
 
Your buns are mine! But you can have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic