here paint method.
public void paint(graphics pane) { pane.setcolor(color.black); pane.drawrect(x, y-height, width, height); if(name!=null) pane.drawstring(getname(), x, y-50); } }
i string returned getname() method bounded within rectangle have created, rather starting rectangle starts writing on edge.
you can use graphics setclip()
method set clipping pane text within rectangle, however, excess clipped off. in order fit have calculate best font size. check out fontmetrics
class calculations.