Example usage for javax.swing AbstractButton getSize

List of usage examples for javax.swing AbstractButton getSize

Introduction

In this page you can find the example usage for javax.swing AbstractButton getSize.

Prototype

public Dimension getSize() 

Source Link

Document

Returns the size of this component in the form of a Dimension object.

Usage

From source file:MyCheckBoxUI.java

public void paint(Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Dimension d = b.getSize();

    g.setFont(c.getFont());/*from ww  w .j a va2s. c o m*/
    FontMetrics fm = g.getFontMetrics();
    g.setColor(Color.white);
    g.drawString("Am I a check box", 10, 10);

}

From source file:MyButtonUI.java

public void paint(Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;
    Dimension d = b.getSize();

    g.setFont(c.getFont());//from  w  ww . ja  va 2  s .  c o m
    FontMetrics fm = g.getFontMetrics();

    g.setColor(b.getForeground());
    String caption = b.getText();
    int x = (d.width - fm.stringWidth(caption)) / 2;
    int y = (d.height + fm.getAscent()) / 2;
    g.drawString(caption, x, y);

}