java JDialog draw called double -


i've got problem makes me go crazy. call method via line of code:

private void btngetfoldermouseclicked(mouseevent e) {     messagecontroller.showalert(alertbox.alerttype.ok); } 

and method called:

public class messagecontroller { public static void showalert(alertbox.alerttype alerttype) {     alertbox alertbox = new alertbox("test12345678910dfkjsdgmdgbu<xdfg<bdxgj ghfhftz rgdx", alerttype);     alertbox.getrootpane().setopaque(false);     //alertbox.getcontentpane ().setbackground (new color(0, 0, 0, 0));     //alertbox.setbackground (new color(0, 0, 0, 0));     alertbox.setvisible(true);  //      bdialog dialog = new bdialog(); //      dialog.setvisible(true);      system.out.println("nach box");     //alertbox.invalidate(); } } 

and here jdialog class:

public class alertbox extends jdialog { private imageicon downside = new imageicon(getclass().getresource("/alertbox/down_side.png")); private imageicon leftdowncorner = new imageicon(getclass().getresource("/alertbox/left_down_corner.png")); private imageicon leftside = new imageicon(getclass().getresource("/alertbox/left_side.png")); private imageicon leftupcorner = new imageicon(getclass().getresource("/alertbox/left_up_corner.png")); private imageicon rightdowncorner = new imageicon(getclass().getresource("/alertbox/right_down_corner.png")); private imageicon rightside = new imageicon(getclass().getresource("/alertbox/right_side.png")); private imageicon rightupcorner = new imageicon(getclass().getresource("/alertbox/right_up_corner.png")); private imageicon upside = new imageicon(getclass().getresource("/alertbox/up_side.png"));  private string text;  private rectangle2d fontsize;  private font font = new font("arial", font.bold, 13);  private imagedbutton btnok;  public enum alerttype{     ok,     warning,     error }  private alerttype alerttype;  public alertbox(string text, alerttype alerttype){      // set jdialog properties     super(new jframe(), true);     setdefaultcloseoperation(do_nothing_on_close);     setundecorated(true);     setlocationrelativeto(null);      this.text = text;     this.alerttype = alerttype;      btnok = new imagedbutton("ok");     btnok.addactionlistener(new actionlistener() {         @override         public void actionperformed(actionevent e) {             system.out.println("button clicked");             exitalertbox();         }     });     //this.add(btnok); }  @override public void paint(graphics g) {     // create graphics2d object     graphics2d g2d = (graphics2d) g.create();      // size     fontsize = stringmetrics.getbounds(g2d, font, text);      // set fontsize     int width = (int) fontsize.getwidth() + 5 + leftside.geticonwidth() + 5 + rightside.geticonwidth();     int height = leftupcorner.geticonheight() + 5 + (int)fontsize.getheight() + 5 + btnok.getheight() + 5 + leftdowncorner.geticonheight();     this.setsize(width, height);      //this.replacebutton(width, height);      // draw left upper corner     system.out.println(leftdowncorner.geticonwidth() + " ; " + leftdowncorner.geticonheight());     g.drawimage(leftupcorner.getimage(), 0, 0, this);     g.drawimage(new imageicon(getclass().getresource("/buttons/button_down.png")).getimage(), 21, 20, this);      // draw upper side     //g.drawimage(upside.getimage(), leftupcorner.geticonwidth(), 0, 5 + (int) fontsize.getwidth() + 5, upside.geticonheight(), this);      // draw right upper corner     //g.drawimage(rightupcorner.getimage(), this.getwidth() - rightupcorner.geticonwidth(), 0, this);      // draw left side     //g.drawimage(leftside.getimage(), 0, leftupcorner.geticonheight(), leftside.geticonwidth(), 5 + (int)fontsize.getheight() + 5, this);      // draw right side     //g.drawimage(rightside.getimage(), width - rightside.geticonwidth(), rightupcorner.geticonheight(), rightside.geticonwidth(), 5 + upside.geticonheight() + 5, this);      // draw left downer corner     //g.drawimage(leftdowncorner.getimage(), 0, height - leftdowncorner.geticonheight(), this);      // draw right downer corner     //g.drawimage(rightdowncorner.getimage(), this.getwidth() - rightupcorner.geticonwidth(), height - rightdowncorner.geticonheight(), this);      // draw downer side     //g.drawimage(downside.getimage(), leftdowncorner.geticonwidth(), height - downside.geticonheight(), 5 + (int) fontsize.getwidth() + 5, downside.geticonheight(), this);        // draw text     //g2d.drawstring(text, 10, 10);     //g2d.drawstring(text, leftupcorner.geticonwidth() + 5, (int)fontsize.getheight() + 8);       if (this.alerttype == alerttype.ok){      } }  private void replacebutton(int width, int height){     // paint ok-button     int testwidth = width - (btnok.getwidth() / 2);     int testheight = height - btnok.getheight() - 5;      btnok.setbounds(testwidth, testheight, btnok.getwidth(), btnok.getheight()); }  private void exitalertbox(){     this.dispose(); } } 

the problem is, window should (at version of code) display 2 images. does.. sometimes.. of runs doesn't.

not showing

showing

when debug code, seems 'paint' method called twice, don't find line happens.

did wrong?

thanks :)


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -