Java JButton fixToolbarButtonImpl(JButton button)

Here you can find the source of fixToolbarButtonImpl(JButton button)

Description

fix Toolbar Button Impl

License

BSD License

Declaration

private static final void fixToolbarButtonImpl(JButton button) throws Exception 

Method Source Code

//package com.java2s;
/*/*ww  w .j  a v a 2s  .  c om*/
 * 03/30/2013
 *
 * WebLookAndFeelUtils.java - Utility methods for applications looking to
 * support WebLookAndFeel.
 * Copyright (C) 2003 Robert Futrell
 * http://fifesoft.com/rtext
 * Licensed under a modified BSD license.
 * See the included license file for details.
 */

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

import javax.swing.plaf.ButtonUI;

public class Main {
    private static final String BUTTON_UI_CLASS_NAME = "com.alee.laf.button.WebButtonUI";
    private static final String STYLE_CONSTANTS_CLASS = "com.alee.laf.StyleConstants";

    private static final void fixToolbarButtonImpl(JButton button) throws Exception {

        ButtonUI ui = button.getUI();

        String clazzName = ui.getClass().getName();
        if (BUTTON_UI_CLASS_NAME.equals(clazzName)) {

            Class<?> uiClazz = ui.getClass();
            Method m = uiClazz.getDeclaredMethod("setRolloverDecoratedOnly", boolean.class);
            m.invoke(ui, true);
            m = uiClazz.getMethod("setRound", int.class);
            ClassLoader cl = uiClazz.getClassLoader();
            Class<?> clazz = Class.forName(STYLE_CONSTANTS_CLASS, true, cl);
            Field smallRound = clazz.getField("smallRound");
            int value = smallRound.getInt(null);
            m.invoke(ui, value);

            // By default, buttons have 4 pixel spacing on their left and
            // right, which looks ridiculous for toolbar buttons.  WebLaF
            // provides factory methods for icon-only buttons to work around
            // this, but we are avoiding WebLaF-specific APIs.
            m = uiClazz.getMethod("setLeftRightSpacing", int.class);
            m.invoke(ui, 0);

        }

    }
}

Related

  1. ensureButtonWidth(JButton button, int width)
  2. enterPressesWhenFocused(final JButton button)
  3. equalizeButtons(JButton... buttons)
  4. exit(JButton aButton)
  5. fixButtonWidth(JButton... buttons)
  6. formatButtonAsLabel(JButton button)
  7. formatJButton(JButton button, String tooltips)
  8. getButtonNumber(JButton btn)
  9. getScrollStroke(final JButton _jlbl_stroke)