aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JMenu text color Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JMenu text color" Watch "JMenu text color" New topic
Author

JMenu text color

Joe McIntyre
Ranch Hand

Joined: Nov 20, 2003
Posts: 121
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?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

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


luck, db
There are no new questions, but there may be new answers.
Joe McIntyre
Ranch Hand

Joined: Nov 20, 2003
Posts: 121
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

Joined: Nov 20, 2003
Posts: 121
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

Joined: Nov 20, 2003
Posts: 121
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

Joined: Nov 20, 2003
Posts: 121
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Joe McIntyre
Ranch Hand

Joined: Nov 20, 2003
Posts: 121
I see... didn't notice the edit button. Will use it next time.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

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.


GenRocket - A Test Data Generation Platform
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

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

Joined: Nov 20, 2003
Posts: 121
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

Joined: Nov 20, 2003
Posts: 121
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JMenu text color
 
Similar Threads
Color
Change color of a LookAndFeel
How to conditionally change text color?
Changing colors on my swing app
focus of JPanel