Tuesday, 15 May 2012

swing - Not able to repaint in java -



swing - Not able to repaint in java -

i not able dynamically repaint() within jframe.

public static bufferedimage createbufferedimage(bufferedimage image) { colormodel cm = image.getcolormodel(); boolean premultiplied = cm.isalphapremultiplied(); writableraster raster = image.copydata(image.getraster()); homecoming new bufferedimage(cm, raster, premultiplied, null); } public static void main(string[] args) { bufferedimage img = new bufferedimage(old_width_i, old_height_i, bufferedimage.type_int_rgb); img=createbufferedimage(img_white_screen); jframe frame=new jframe(); jlabel label = new jlabel(new imageicon(img)); frame.getcontentpane().add(label, borderlayout.west); frame.pack(); frame.setvisible(true); frame.setdefaultcloseoperation(jframe.exit_on_close); seek { thread.sleep(1000); } grab (interruptedexception e) { // todo auto-generated grab block e.printstacktrace(); } img.flush(); img=createbufferedimage(img_black_screen); // frame.removeall(); // frame.revalidate(); // label.removeall(); // label = new jlabel(new imageicon(img)); // frame.getcontentpane().add(label, borderlayout.west); frame.repaint(); }

it basically, creates screen first assignment "img" (i.e. img_white_screen) variable , not alter sec assignment i.e. img_black_screen

don't utilize thread.sleep(1000);, code line lock event dispatch thread,

no thought why reason need pause code execution 1 second, use swing timer instead

for showing image in java utilize

xxximage icon /iconimage jlabel

paintcomponent() jcomponent or jpanel

don't paint xxximage or icon / imageicon straight jframe, utilize jpanel / jcomponent or jlabel

java swing jframe repaint

No comments:

Post a Comment