Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.gui Subject: Re: Anybody know how to set the color of the text in a disabled JMenuItem? Date: Thu, 18 Aug 2011 16:06:20 -0700 Organization: A noiseless patient Spider Lines: 52 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 18 Aug 2011 23:06:22 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="5817"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+U0dY0PJ6Hju0u7+hegUqO" User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: Cancel-Lock: sha1:w62AnCtT9yo4rrEgN2J1w4DJEWE= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4639 On 8/18/2011 2:38 PM, markspace wrote: > On 8/18/2011 11:39 AM, Knute Johnson wrote: >> I assume what I'm trying to find is in AbstractButton somewhere. I need >> a disabled JMenuItem with brighter text. One can set the background of a >> disabled JMenuItem but not the foreground. > > > I don't see anyway to differentiate the foreground color of a menu item > when it's enabled vs when it's disabled. You could use a change > listener, which will fire whenever the state is changed from enabled to > disabled or vice-versa. > > JMenuItem jMenuItem2 = ... > > jMenuItem2.addChangeListener(new javax.swing.event.ChangeListener() > { > public void stateChanged(javax.swing.event.ChangeEvent evt) { > jMenuItem2StateChanged(evt); > } > }); > > ... > > private void jMenuItem2StateChanged( > javax.swing.event.ChangeEvent evt) > { > System.out.println( "jMenuItem2StateChanged - "+ evt ); > JMenuItem jm = ((JMenuItem)evt.getSource()); > System.out.println( "Enabled: "+jm.isEnabled() ); > > if( jm.isEnabled() ) { > jm.setForeground( Color.red ); > } else { > jm.setForeground( Color.yellow ); > } > > } > > This seemed to work reliably for me, changing the menu text color from > red when enabled and yellow ("brighter") when disabled. You could > encapsulate this into a new kind of JMenuItem if you need it really > frequently, I suppose. > > Thanks for that but apparently I asked the wrong question. Why can't I change the foreground color on my JMenuItem like you can? I'm running 1.7 on Windows XP. It may be something different with the LookAndFeel. -- Knute Johnson