Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4638

Re: Anybody know how to set the color of the text in a disabled JMenuItem?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From markspace <-@.>
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 14:38:35 -0700
Organization A noiseless patient Spider
Lines 43
Message-ID <j2k0p5$5ru$1@dont-email.me> (permalink)
References <j2jm9m$qgt$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Thu, 18 Aug 2011 21:38:45 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="6014"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lkHNZ6I3Rd7GeEqs7l8jlLdvH1CcyFps="
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0
In-Reply-To <j2jm9m$qgt$1@dont-email.me>
Cancel-Lock sha1:b0umIdLAVlZnYKDkZ5WToF9+pbw=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4638

Show key headers only | View raw


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.

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Anybody know how to set the color of the text in a disabled JMenuItem? Knute Johnson <september@knutejohnson.com> - 2011-08-18 11:39 -0700
  Re: Anybody know how to set the color of the text in a disabled JMenuItem? markspace <-@.> - 2011-08-18 14:38 -0700
    Re: Anybody know how to set the color of the text in a disabled JMenuItem? Knute Johnson <september@knutejohnson.com> - 2011-08-18 16:06 -0700
      Re: Anybody know how to set the color of the text in a disabled JMenuItem? markspace <-@.> - 2011-08-18 18:52 -0700
        Re: Anybody know how to set the color of the text in a disabled JMenuItem? "John B. Matthews" <nospam@nospam.invalid> - 2011-08-19 07:01 -0400
          Re: Anybody know how to set the color of the text in a disabled JMenuItem? Knute Johnson <september@knutejohnson.com> - 2011-08-19 09:39 -0700
            Re: Anybody know how to set the color of the text in a disabled JMenuItem? markspace <-@.> - 2011-08-19 10:49 -0700
            Re: Anybody know how to set the color of the text in a disabled JMenuItem? "John B. Matthews" <nospam@nospam.invalid> - 2011-08-20 03:45 -0400
              Re: Anybody know how to set the color of the text in a disabled JMenuItem? Knute Johnson <september@knutejohnson.com> - 2011-08-20 14:16 -0700
                Re: Anybody know how to set the color of the text in a disabled JMenuItem? "John B. Matthews" <nospam@nospam.invalid> - 2011-08-20 21:17 -0400
              Re: Anybody know how to set the color of the text in a disabled JMenuItem? Knute Johnson <september@knutejohnson.com> - 2011-08-20 14:28 -0700
        Re: Anybody know how to set the color of the text in a disabled JMenuItem? Tom <tom400f@gmail.com> - 2011-08-19 17:16 +0000
          Re: Anybody know how to set the color of the text in a disabled JMenuItem? Knute Johnson <september@knutejohnson.com> - 2011-08-19 11:03 -0700

csiph-web