Search in sources :

Example 1 with BasicButtonListener

use of javax.swing.plaf.basic.BasicButtonListener in project gephi by gephi.

the class UIUtils method fixButtonUI.

// Classic Windows LaF doesn't draw dotted focus rectangle inside JButton if parent is JToolBar,
// XP Windows LaF doesn't draw dotted focus rectangle inside JButton at all
// This method installs customized Windows LaF that draws dotted focus rectangle inside JButton always
// On JDK 1.5 the XP Windows LaF enforces special border to all buttons, overriding any custom border
// set by setBorder(). Class responsible for this is WindowsButtonListener. See Issue 71546.
// Also fixes buttons size in JToolbar.
/**
     * Ensures that focus will be really painted if button is focused and fixes
     * using custom border for JDK 1.5 and XP LaF
     * @param button button
     */
public static void fixButtonUI(AbstractButton button) {
    // JButton
    if (button.getUI() instanceof com.sun.java.swing.plaf.windows.WindowsButtonUI) {
        button.setUI(new com.sun.java.swing.plaf.windows.WindowsButtonUI() {

            @Override
            protected BasicButtonListener createButtonListener(AbstractButton b) {
                // Fix for  Issue 71546
                return new BasicButtonListener(b);
            }

            @Override
            protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
                int width = b.getWidth();
                int height = b.getHeight();
                g.setColor(getFocusColor());
                javax.swing.plaf.basic.BasicGraphicsUtils.drawDashedRect(g, dashedRectGapX, dashedRectGapY, width - dashedRectGapWidth, height - dashedRectGapHeight);
            }
        });
    } else // JToggleButton
    if (button.getUI() instanceof com.sun.java.swing.plaf.windows.WindowsToggleButtonUI) {
        button.setUI(new com.sun.java.swing.plaf.windows.WindowsToggleButtonUI() {

            @Override
            protected BasicButtonListener createButtonListener(AbstractButton b) {
                // Fix for  Issue 71546
                return new BasicButtonListener(b);
            }

            @Override
            protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect) {
                int width = b.getWidth();
                int height = b.getHeight();
                g.setColor(getFocusColor());
                javax.swing.plaf.basic.BasicGraphicsUtils.drawDashedRect(g, dashedRectGapX, dashedRectGapY, width - dashedRectGapWidth, height - dashedRectGapHeight);
            }
        });
    }
}
Also used : AbstractButton(javax.swing.AbstractButton) BasicButtonListener(javax.swing.plaf.basic.BasicButtonListener) Rectangle(java.awt.Rectangle) Graphics(java.awt.Graphics)

Aggregations

Graphics (java.awt.Graphics)1 Rectangle (java.awt.Rectangle)1 AbstractButton (javax.swing.AbstractButton)1 BasicButtonListener (javax.swing.plaf.basic.BasicButtonListener)1