private static Object applyToField( Field f, Object obj, Object value, boolean useMethodHandles )
		throws IllegalArgumentException
	{
		checkValidField( f );

		if( useMethodHandles && obj instanceof StyleableLookupProvider ) {
			try {
				// use method handles to access protected fields in JRE in modular applications
				MethodHandles.Lookup lookup = ((StyleableLookupProvider)obj).getLookupForStyling();

				// get old value and set new value
				Object oldValue = lookup.unreflectGetter( f ).invoke( obj );
				lookup.unreflectSetter( f ).invoke( obj, convertToEnum( value, f.getType() ) );
				return oldValue;
			} catch( Throwable ex ) {
				throw newFieldAccessFailed( f, ex );
			}
		}

		try {
			// necessary to access protected fields in other packages
			f.setAccessible( true );

			// get old value and set new value
			Object oldValue = f.get( obj );
			f.set( obj, convertToEnum( value, f.getType() ) );
			return oldValue;
		} catch( IllegalAccessException ex ) {
			throw newFieldAccessFailed( f, ex );
		}
	}
Applies the given value to a field of the given object.

@param obj the object
@param fieldName the name of the field
@param key the key (only used for error reporting)
@param value the new value
@return the old value of the field
@throws UnknownStyleException if object does not have a field with given name
@throws IllegalArgumentException if value type does not fit to expected type
flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatStylingSupport.java