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


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

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From Knute Johnson <september@knutejohnson.com>
Newsgroups comp.lang.java.gui
Subject Re: Anybody know how to set the color of the text in a disabled JMenuItem?
Date Fri, 19 Aug 2011 09:39:54 -0700
Organization A noiseless patient Spider
Lines 80
Message-ID <j2m3kp$1c3$1@dont-email.me> (permalink)
References <j2jm9m$qgt$1@dont-email.me> <j2k0p5$5ru$1@dont-email.me> <j2k5te$5lp$1@dont-email.me> <j2kfm1$tai$1@dont-email.me> <nospam-C33427.07014719082011@news.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Fri, 19 Aug 2011 16:39:53 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="1411"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Cl6/GPFOA49qVuDisVQXr"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20110812 Thunderbird/6.0
In-Reply-To <nospam-C33427.07014719082011@news.aioe.org>
Cancel-Lock sha1:Un83ClhZZ2czKNIGm7MpeUekNZI=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4643

Show key headers only | View raw


On 8/19/2011 4:01 AM, John B. Matthews wrote:
> In article<j2kfm1$tai$1@dont-email.me>, markspace<-@.>  wrote:
>
>> On 8/18/2011 4:06 PM, Knute Johnson wrote:
>>
>>> 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.
>>
>>
>> I'm running Java 7 on Windows 7.  My LNF is just the default one
>> (might be Synth).  I was running within NetBeans 7.0.1 IDE.  Can't
>> say why it doesn't work for you.
>
> Have the related UI defaults for MenuItem.* changed?

I don't know.

> <http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/>

I hadn't remembered that technique for changing the defaults but I only 
want to change one JMenuItem's disabled foreground color.  That defaults 
do work just fine to change them all.  I tried setting a new UI on the 
JMenuItem but that doesn't seem to work either (see SSCCE below).  When 
I started this I didn't think it was going to take two days of messing 
around with it :-).

import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;

public class test extends JFrame {
     public test() {
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

         JMenuBar mb = new JMenuBar();
         setJMenuBar(mb);

         JMenu menu = new JMenu("test");
         mb.add(menu);

         JMenuItem mi = new JMenuItem("This is default disabled");
         mi.setEnabled(false);
         menu.add(mi);

         class NewUI extends BasicMenuItemUI {
             public NewUI() {
                 disabledForeground = Color.RED;
             }
         };

         mi = new JMenuItem("This I want to be bright red");
         mi.setEnabled(false);
         mi.setUI(new NewUI());
         menu.add(mi);

         JPanel p = new JPanel();
         p.setPreferredSize(new Dimension(100,100));
         add(p);

         pack();
         setVisible(true);
     }

     public static void main(String[] args) {
         EventQueue.invokeLater(new Runnable() {
             public void run() {
                 new test();
             }
         });
     }
}

Thanks,

-- 

Knute Johnson

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