public void paint(Graphics g, JComponent c) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); String text = layout(b, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight()); clearTextShiftOffset(); // perform UI specific press action, e.g. Windows L&F shifts text if (model.isArmed() && model.isPressed()) { paintButtonPressed(g, b); } // Paint the Icon if (b.getIcon() != null) { paintIcon(g, c, iconRect); } if (text != null && !text.equals("")) { View v = (View) c.getClientProperty(BasicHTML.propertyKey); if (v != null) { v.paint(g, textRect); } else { paintText(g, b, textRect, text); } } if (b.isFocusPainted() && b.hasFocus()) { // paint UI specific focus paintFocus(g, b, viewRect, textRect, iconRect); } }
/** * Return true if this button should render as if it has the keyboard focus. This first checks the * HAS_FOCUS client property to determine if an artificial state is being induced; if that is * undefined then the button's hasFocus() method is consulted. */ protected static boolean hasFocus(AbstractButton button) { Boolean hasFocus = (Boolean) button.getClientProperty(HAS_FOCUS); if (hasFocus == null) hasFocus = button.hasFocus(); return hasFocus; }