Java JComponent Container getGtkStyle(Object styleFactory, JComponent component, String regionName)

Here you can find the source of getGtkStyle(Object styleFactory, JComponent component, String regionName)

Description

Called internally by installGtkPopupBugWorkaround.

License

Apache License

Parameter

Parameter Description
styleFactory The GTK style factory.
component The target component of the style.
regionName The name of the target region of the style.

Exception

Parameter Description
Exception When reflection fails.

Return

The GTK style.

Declaration

private static Object getGtkStyle(Object styleFactory, JComponent component, String regionName)
        throws Exception 

Method Source Code


//package com.java2s;
/*//from w ww. j  a v a2s  .co  m
 * PlatformHelper.java
 *
 * This file is part of SQL Workbench/J, http://www.sql-workbench.net
 *
 * Copyright 2002-2017, Thomas Kellerer
 *
 * Licensed under a modified Apache License, Version 2.0
 * that restricts the use for certain governments.
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at.
 *
 *     http://sql-workbench.net/manual/license.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * To contact the author please send an email to: support@sql-workbench.net
 *
 */

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import javax.swing.JComponent;

public class Main {
    /**
     * Called internally by installGtkPopupBugWorkaround. Returns a specific GTK style object.
     *
     * @param styleFactory The GTK style factory.
     * @param component The target component of the style.
     * @param regionName The name of the target region of the style.
     * @return The GTK style.
     * @throws Exception When reflection fails.
     */
    private static Object getGtkStyle(Object styleFactory, JComponent component, String regionName)
            throws Exception {
        // Create the region object
        Class<?> regionClass = Class.forName("javax.swing.plaf.synth.Region");
        Field field = regionClass.getField(regionName);
        Object region = field.get(regionClass);

        // Get and return the style
        Class<?> styleFactoryClass = styleFactory.getClass();
        Method method = styleFactoryClass.getMethod("getStyle", new Class<?>[] { JComponent.class, regionClass });
        boolean accessible = method.isAccessible();
        method.setAccessible(true);
        Object style = method.invoke(styleFactory, component, region);
        method.setAccessible(accessible);
        return style;
    }
}

Related

  1. getDataFlavors(JComponent component)
  2. getDeepestEmptyComponentAt(JComponent parent, Point location)
  3. getFirstChildComponentOfType(Component component, Class childComponentType)
  4. getGlassPane(JComponent comp)
  5. getGtkStyle(Object styleFactory, JComponent component, String regionName)
  6. getInputHint(JComponent comp)
  7. getInsetBounds(JComponent comp)
  8. getInterior(JComponent comp)
  9. getLocalInsetBounds(JComponent component)