java - Overriding JButton paintComponent with differnet style not suporting HTML format -
i want set different style jbutton. overridden paintcomponent achieve. works successful button doesn't support html format.
could please suggest me
paintcomponent() ~~~~~~~~~~~~~~~~ below override code: // prep painting. graphics2d g2d = (graphics2d)g; if(buttonstyle != 0 && buttonstyle != images){ if(g == null) return; if(getbackground() == null) setbackground(acrcolor); if(getfadedbackgroundcolor() == null) setfadedbackgroundcolor(color.white); g2d.clearrect(0, 0, getwidth()+getx(), getheight()+gety()); // end prep painting. } switch (buttonstyle){ case skinz: paintskinz(g2d); return; case images: paintimages(g2d); break; case rollover: system.err.println("rollover of fuelbutton not yet implemented."); break; case java_like: paintjavalike(g2d); return; case gradience: paintgradience(g2d); case classic: case java_default: default: super.paintcomponent(g); m_originalborder = getborder(); m_originalfont = getfont(); return; } painttext(g2d,0,0,getwidth(),getheight()); paintjavalike(g2d): ~~~~~~~~~~~~~~~~~~~~ g2d.setcolor(getbackground()); g2d.fill3drect(0,0,getwidth(),getheight(),true); if(geticon()==null) painttext(g2d,0,0,getwidth(),getheight()); else if (gettext() == null || gettext().length() == 0) this.paintcenteredicon(g2d, ((imageicon)geticon()).getimage()); else { int w = getwidth() - geticontextgap() - geticon().geticonwidth() - (borderwidth*2)-4; int h = getheight()-(borderwidth*2); g2d.drawimage(((imageicon)geticon()).getimage(), 2, (getheight()/2)-(geticon().geticonheight()/2), this); painttext(g2d,2+geticon().geticonwidth()+this.geticontextgap(),0,w,h); }
thanks palanisamy
you provide custom buttonui, , use buttons, instead of overriding paintcomponent()
. swing uses textlayout
drawing strings, , can complicated. however, basicbuttonui has protected painttext()
method can want (you don't need call manually. ui's paint()
calls it, unless override too). if extend basicbuttonui
can let draw string.
Comments
Post a Comment