java - Load an image into a JPanel in an applet -


base on thread :java: load image file, edit , add jpanel tried load na image jpanel not painting it,so here s deal, suggested have created new class file named jimagecomponent extends jcomponent, looks :

package in.co.sneh; import java.awt.graphics; import java.awt.image.bufferedimage; import javax.swing.jcomponent; private bufferedimage img;     public class jimagecomponent  extends jcomponent {     public jimagecomponent (bufferedimage bi) {     img = bi; }  @override public void paintcomponent(graphics g) {     g.drawimage(img, 0, 0, this); } } 

then in applet form class ,when click on loadpicture button, action performed looks :

jfilechooser chooser = new jfilechooser();     chooser.setfileselectionmode(jfilechooser.files_and_directories);    int retval = chooser.showdialog(appletform.this, "attach");     if (retval == jfilechooser.approve_option) {         picfile = chooser.getselectedfile();         try {              image = imageio.read(picfile);             jimagecomponent jcomp = new jimagecomponent(image);             graphics2d g = image.creategraphics();             jcomp.paintcomponents(g);             // draw here on graphics             //g.dispose();             g.setrenderinghint(renderinghints.key_antialiasing,              renderinghints.value_antialias_on);             jpanel6.add(jcomp);             system.out.println("testing" + picfile);            } catch (ioexception e) {              e.printstacktrace();         } 

to me in place image not showing when in file explorer choose image, can me out? in advance, romulo romero

after adding new component container, need call

jpanel6.revalidate(); jpanel6.repaint(); 

also applets cannot load resources local file system unless signed.

note: while having a single jimagecomponent better, jlabel components offer functionality of switching images using seticon.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -