Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: Tom 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 17:16:24 +0000 (UTC) Organization: Aioe.org NNTP Server Lines: 33 Message-ID: References: NNTP-Posting-Host: Vd3zjYYo2heJAT9ZVcrkiA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Pan/0.133 (House of Butterflies) X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4644 On Thu, 18 Aug 2011 18:52:55 -0700, 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. BasicMenuItemUI has this: protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) { ButtonModel model = menuItem.getModel(); FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g); int mnemIndex = menuItem.getDisplayedMnemonicIndex(); if(!model.isEnabled()) { // *** paint the text disabled if ( UIManager.get("MenuItem.disabledForeground") instanceof Color ) { g.setColor( UIManager.getColor("MenuItem.disabledForeground") ); SwingUtilities2.drawStringUnderlineCharAt(menuItem, g,text, mnemIndex, textRect.x, textRect.y + fm.getAscent()); } else { ... so it doesn't appear to use the disabledForeground member anyway. Perhaps that is your problem? Of course, other L&F may do different things.