On Dec 1, 9:21 pm, Knute Johnson<nos...@knutejohnson.com> wrote:
On 12/1/2011 8:37 AM, Fred wrote:
On Nov 30, 4:11 pm, Knute Johnson<nos...@knutejohnson.com>
wrote:
On 11/30/2011 9:15 AM, Fred wrote:
To change colors on some JComponents using Nimbus L&F, I have
to use a custom Painter.
I followed the examples of Jasper Potts, and imported from
com.sun.java.swing.Painter
But on some Java implementations this could not be resolved.
Then I found the same definition in
org.jdesktop.swingx.painter.Painter
Which should be used? Why? Which is "correct"? Is there a
true standard Java?
-- Fred K
Both of those packages are not part of the public API and you
could expect that they would not necessarily remain or be
correct in the future.
But I'm curious, on what JComponents could you not set the
color?
I use a Painter to set the selected tab color for a JTabbedPane.
-- Fred K
The setForegroundAt() and setBackgroundAt() methods don't work with
Nimbus?
That's not exactly what I want, but no, they do not. What I want is
to specify that whichever tab is selected should be displayed with a
specific color, regardless of which tab is selected. Before we
switched to Nimbus, that is done by a simple call: UIManager.put(
"TabbedPane.selected", selectedColor );
Using Nimbus, that does not work. My solution is very awkward (sorry
about the wrapping; here, "component" is the JTabbedPane):
UIDefaults def = new UIDefaults(); selectedTabPainter = new
Painter<JComponent>() { public void paint( Graphics2D g, JComponent
c, int w, int h ) { paintTab( g, selectedColor, w, h, true ); } };
def.put( "TabbedPane:TabbedPaneTab[Disabled
+Selected].backgroundPainter", selectedTabPainter ); def.put(
"TabbedPane:TabbedPaneTab[Focused+MouseOver
+Selected].backgroundPainter", selectedTabPainter ); def.put(
"TabbedPane:TabbedPaneTab[Focused +Selected].backgroundPainter",
selectedTabPainter ); def.put( "TabbedPane:TabbedPaneTab[Pressed
+Selected].backgroundPainter", selectedTabPainter );
def.put( "TabbedPane:TabbedPaneTab[Selected].backgroundPainter",
selectedTabPainter ); def.put( "TabbedPane:TabbedPaneTab[MouseOver
+Selected].backgroundPainter", selectedTabPainter ); // // include
Focused+Pressed+Selected if you want the selected tab to // stay the
selected color when the user presses the mouse in the // current
selected tab // def.put( "TabbedPane:TabbedPaneTab[Focused+Pressed
+Selected].backgroundPainter", selectedTabPainter );
component.putClientProperty( "Nimbus.Overrides", def );
component.putClientProperty( "Nimbus.Overrides.InheritDefaults",
false );
-- Fred K
couldn't. As sad as it sounds, I think that's the only way.