Example usage for java.awt Toolkit getClass

List of usage examples for java.awt Toolkit getClass

Introduction

In this page you can find the example usage for java.awt Toolkit getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:de.ailis.xadrian.utils.SwingUtils.java

/**
 * Sets the application name. There is no API for this (See
 * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6528430) so this
 * method uses reflection to do this. This may fail if the Java
 * implementation is changed but any exception here will be ignored.
 * /* ww w .j av a2 s .  co  m*/
 * The application name is currently only used for X11 desktops and only
 * important for some window managers like Gnome Shell.
 * 
 * @param appName
 *            The application name to set.
 */
public static void setAppName(final String appName) {
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Class<?> cls = toolkit.getClass();

    try {
        // When X11 toolkit is used then set the awtAppClassName field
        if (cls.getName().equals("sun.awt.X11.XToolkit")) {
            final Field field = cls.getDeclaredField("awtAppClassName");
            field.setAccessible(true);
            field.set(toolkit, appName);
        }
    } catch (final Exception e) {
        LOG.warn("Unable to set application name: " + e, e);
    }
}

From source file:org.executequery.ApplicationLauncher.java

private void x11Settings() {

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Class<?> xtoolkit = toolkit.getClass();
    if (xtoolkit.getName().equals("sun.awt.X11.XToolkit")) {

        try {/*w  ww  .j  a v  a 2s  .  c  om*/

            Field awtAppClassName = xtoolkit.getDeclaredField("awtAppClassName");
            awtAppClassName.setAccessible(true);
            awtAppClassName.set(null, ExecuteQueryFrame.TITLE);

        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    /*
    try {
    Toolkit xToolkit = Toolkit.getDefaultToolkit();
    java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
    awtAppClassNameField.setAccessible(true);
    awtAppClassNameField.set(xToolkit, "Execute Query");
    } catch (Exception e) {
    e.printStackTrace();
    }
    */

}

From source file:pcgen.gui2.tools.Utility.java

/**
 * This method is used to set the name of the application for the window manager, especially X11.
 *
 * @param title Title to use// ww  w .j  a v  a  2s. c  om
 */
public static void setApplicationTitle(String title) {
    Toolkit xToolkit = Toolkit.getDefaultToolkit();

    try {
        Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName"); //$NON-NLS-1$
        awtAppClassNameField.setAccessible(true);
        awtAppClassNameField.set(xToolkit, title);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        // Rather than do a OS system condition, just ignore this expected exception
        //Logging.log(Level.FINEST, "Can not set name of application for window manager", e);
    }
}

From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java

protected static void initializeLaF() {
    invokeSwingAndWait(() -> {/*from ww  w .  ja v a2s.  c om*/
        try {
            UIManager.setLookAndFeel(LIGHT_THEME);
            SubstanceCortex.GlobalScope.setColorizationFactor(1.0D);
            SubstanceCortex.GlobalScope.registerComponentPlugin(new SubstanceSwingxPlugin());

            if (System.getProperty("os.name").toLowerCase().equals("linux")) {
                // Try to apply GNOME Shell fix
                try {
                    final Toolkit xToolkit = Toolkit.getDefaultToolkit();
                    java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass()
                            .getDeclaredField("awtAppClassName");
                    awtAppClassNameField.setAccessible(true);
                    awtAppClassNameField.set(xToolkit, Lang.get("title"));
                    awtAppClassNameField.setAccessible(false);
                } catch (final Exception e) {
                    LOG.warn("Could not apply X fix", e);
                }
            }

        } catch (final Exception e) {
            LOG.warn("Could not apply Substance LaF, falling back to system LaF", e);
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (final Exception e1) {
                LOG.warn("Failed to load System LaF as well, falling back to keeping the default LaF", e1);
            }
        }
    });
}