mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
Extras: FlatInspector: fixed missing "UI" row on Java 9+
This commit is contained in:
@@ -44,6 +44,7 @@ import java.awt.event.WindowListener;
|
|||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.beans.PropertyChangeSupport;
|
import java.beans.PropertyChangeSupport;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JLayeredPane;
|
import javax.swing.JLayeredPane;
|
||||||
@@ -64,6 +65,7 @@ import javax.swing.plaf.UIResource;
|
|||||||
import javax.swing.text.JTextComponent;
|
import javax.swing.text.JTextComponent;
|
||||||
import com.formdev.flatlaf.FlatClientProperties;
|
import com.formdev.flatlaf.FlatClientProperties;
|
||||||
import com.formdev.flatlaf.ui.FlatUIUtils;
|
import com.formdev.flatlaf.ui.FlatUIUtils;
|
||||||
|
import com.formdev.flatlaf.util.SystemInfo;
|
||||||
import com.formdev.flatlaf.util.UIScale;
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -478,9 +480,17 @@ public class FlatInspector
|
|||||||
|
|
||||||
if( c instanceof JComponent ) {
|
if( c instanceof JComponent ) {
|
||||||
try {
|
try {
|
||||||
Field f = JComponent.class.getDeclaredField( "ui" );
|
Object ui;
|
||||||
f.setAccessible( true );
|
if( SystemInfo.isJava_9_orLater ) {
|
||||||
Object ui = f.get( c );
|
// Java 9+: use public method JComponent.getUI()
|
||||||
|
Method m = JComponent.class.getMethod( "getUI" );
|
||||||
|
ui = m.invoke( c );
|
||||||
|
} else {
|
||||||
|
// Java 8: read protected field 'ui'
|
||||||
|
Field f = JComponent.class.getDeclaredField( "ui" );
|
||||||
|
f.setAccessible( true );
|
||||||
|
ui = f.get( c );
|
||||||
|
}
|
||||||
appendRow( buf, "UI", (ui != null ? toString( ui.getClass(), classHierarchy ) : "null") );
|
appendRow( buf, "UI", (ui != null ? toString( ui.getClass(), classHierarchy ) : "null") );
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
// ignore
|
// ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user