mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
Styling: fixed IllegalAccessException when using component specific style [style]Spinner = foreground: #f00 and spinner labels are painted (caused by private subclass of JLabel where getForeground() is overridden)
This commit is contained in:
@@ -485,6 +485,7 @@ public class FlatStylingSupport
|
|||||||
String getterName = buildMethodName( "get", name );
|
String getterName = buildMethodName( "get", name );
|
||||||
String setterName = buildMethodName( "set", name );
|
String setterName = buildMethodName( "set", name );
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
try {
|
try {
|
||||||
Method getter;
|
Method getter;
|
||||||
try {
|
try {
|
||||||
@@ -499,10 +500,21 @@ public class FlatStylingSupport
|
|||||||
} catch( NoSuchMethodException ex ) {
|
} catch( NoSuchMethodException ex ) {
|
||||||
throw new UnknownStyleException( name );
|
throw new UnknownStyleException( name );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
|
if( ex instanceof IllegalAccessException ) {
|
||||||
|
// this may happen for private subclasses of public Swing classes
|
||||||
|
// that override public property getter/setter
|
||||||
|
// e.g. class JSlider.SmartHashtable.LabelUIResource.getForeground()
|
||||||
|
// --> try again with superclass
|
||||||
|
cls = cls.getSuperclass();
|
||||||
|
if( cls != null && cls != Object.class )
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException( "failed to invoke property methods '" + cls.getName() + "."
|
throw new IllegalArgumentException( "failed to invoke property methods '" + cls.getName() + "."
|
||||||
+ getterName + "()' or '" + setterName + "(...)'", ex );
|
+ getterName + "()' or '" + setterName + "(...)'", ex );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String buildMethodName( String prefix, String name ) {
|
private static String buildMethodName( String prefix, String name ) {
|
||||||
int prefixLength = prefix.length();
|
int prefixLength = prefix.length();
|
||||||
|
|||||||
@@ -219,6 +219,19 @@ public class TestFlatStyleType
|
|||||||
assertEquals( new Color( 0x000022 ), c.getForeground() );
|
assertEquals( new Color( 0x000022 ), c.getForeground() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void slider2() {
|
||||||
|
JSlider c = new JSlider();
|
||||||
|
|
||||||
|
// when slider labels are painted, then a Java private subclass of JLabel
|
||||||
|
// is used that overrides getForeground(), which is not accessible via reflection
|
||||||
|
// see class JSlider.SmartHashtable.LabelUIResource
|
||||||
|
c.setPaintLabels( true );
|
||||||
|
c.setMajorTickSpacing( 50 );
|
||||||
|
|
||||||
|
assertEquals( new Color( 0x000022 ), c.getForeground() );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void spinner() {
|
void spinner() {
|
||||||
JSpinner c = new JSpinner();
|
JSpinner c = new JSpinner();
|
||||||
|
|||||||
Reference in New Issue
Block a user