List of usage examples for javax.swing AbstractButton getSize
public Dimension getSize()
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); }