java - paintBorder overridden method not getting called -


i have following piece of code,

customborderfactory.java

import java.awt.color; import java.awt.component; import java.awt.graphics;  import javax.swing.border.border; import javax.swing.border.etchedborder;  public class customborderfactory extends etchedborder {      private static final long serialversionuid = 1l;      @override     public void paintborder(component c, graphics g, int x, int y, int width,             int height) {         system.err.println("painting here");         int w = width;         int h = height;          g.translate(x, y);          g.setcolor(etchtype == lowered ? getshadowcolor(c)                 : gethighlightcolor(c));         g.drawrect(0, 0, w - 2, h - 2);          g.setcolor(etchtype == lowered ? gethighlightcolor(c)                 : getshadowcolor(c));         g.drawline(1, h - 3, 1, 1);         g.drawline(1, 1, w - 3, 1);          g.drawline(0, h - 1, w - 1, h - 1);         g.drawline(w - 1, h - 1, w - 1, 0);          g.translate(-x, -y);     }      public static border createetchedborder(color black, color red) {         return new etchedborder(black, red);     } } 

the problem , overridden paintborder not getting called.

in test code ,

jpanel panel = new jpanel(); panel.setborder(customborderfactory.createetchedborder(color.black,color.red)); 

why paintborder method in customborderfactory class not getting called. (i can sys.err not getting printed) though overridden , still calls super class method.

am new java. please help!

your method returns plain etchedborder :

public static border createetchedborder(color black, color red) {         return new etchedborder(black, red);     } 

what want returning instance of custom class :

public static border createetchedborder(color black, color red) {         return new customborderfactory(black, red);     } 

note name of class confusing, should create custometchedborder class extending etchedborder, real factory class customborderfactory, return instance of custometchedborderwhen call createetchedborder().


Comments