Extending BasicButtonUI
Hi all,
I'm trying to get a custom look for JButtons by extending the BasicButtonUI, and I
get the look, but the JButton refuses to visually react to mouse clicks, i.e. actionListeners are
informed but thepaintButtonPressed method below is never called.
Listed below are the methods that I've overridden.
Any ideas?
Thanks,
Shivchow.
publicvoid paint(Graphics g, JComponent c){
paintComponent(g,c,c.getBackground(),false);
paintText(g,c,c.getBounds(), ((AbstractButton)c).getText());
}
publicvoid paintButtonPressed(Graphics g, AbstractButton b){
System.out.println("paintpressed called");
paintComponent(g, b, b.getBackground(),true);
paintText(g,b,b.getBounds(), b.getText());
}
publicvoid paintText(Graphics g, JComponent c, Rectangle textRect, String text){
FontRenderContext frc =new FontRenderContext(null,true,true);
TextLayout tl =new TextLayout(text, ((AbstractButton) c).getFont(), frc);
int sw = (int) tl.getOutline(null).getBounds().getWidth();
int sh = (int) tl.getOutline(null).getBounds().getHeight();
int xs = (textRect.width-sw)/2;
int ys = (textRect.height+sh-4)/2;
//g.translate(textRect.x, textRect.y);
g.setColor(c.getForeground());
g.drawString(text, xs, ys);
}
protectedvoid paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect){
System.out.println("Focus paint");
}
publicvoid paintBorder(Graphics g){
System.out.println("Border paint");
}
publicvoid paintIcon(Graphics g, JComponent c, Rectangle iconRect){
System.out.println("Icon paint");
}

