public static ComponentUI getUI( JComponent c ) {
		try {
			// Java 9+
			if( SystemInfo.isJava_9_orLater ) {
				if( !getUIMethodInitialized ) {
					getUIMethodInitialized = true;

					try {
						MethodType mt = MethodType.methodType( ComponentUI.class, new Class[0] );
						getUIMethod = MethodHandles.publicLookup().findVirtual( JComponent.class, "getUI", mt );
					} catch( Exception ex ) {
						// ignore
						LoggingFacade.INSTANCE.logSevere( null, ex );
					}
				}

				if( getUIMethod != null )
					return (ComponentUI) getUIMethod.invoke( c );
			}

			// components often used (e.g. as view in scroll panes)
			if( c instanceof JPanel )
				return ((JPanel)c).getUI();
			if( c instanceof JList )
				return ((JList<?>)c).getUI();
			if( c instanceof JTable )
				return ((JTable)c).getUI();
			if( c instanceof JTree )
				return ((JTree)c).getUI();
			if( c instanceof JTextComponent )
				return ((JTextComponent)c).getUI();

			// Java 8 and fallback
			Method m = c.getClass().getMethod( "getUI" );
			return (ComponentUI) m.invoke( c );
		} catch( Throwable ex ) {
			// ignore
			return null;
		}
	}
Java 8: getUI() method on various components (e.g. JButton, JList, etc)
<br>
Java 9: javax.swing.JComponent.getUI()
flatlaf-core/src/main/java/com/formdev/flatlaf/ui/JavaCompatibility2.java