JAVA JPanel not displaying image -
i playing around reading image (a google street view) url , adding jpanel. start, taking url "https://maps.googleapis.com/maps/api/streetview?size=600x300&location=46.414382,10.013988" , trying read image add image jpanel display. not receiving compilation or runtime errors, jpanel never pops cannot tell if image on or not. ideas here?
edit: clarify, want pop new window containing image read in url, not add image existing panel
url url = new url("https://maps.googleapis.com/maps/api/streetview?size=600x300&location=46.414382,10.013988"); bufferedimage streetview = imageio.read(url); jlabel label = new jlabel(new imageicon(streetview)); jpanel panel = new jpanel(); panel.add(label); panel.setlocation(0,0); panel.setvisible(true);
i want pop new window display image in url, not add existing frame
i asked why expect display window, , stated,
i expect because have instantiated , call setvisible on it.
understand jpanel container component holds other components doesn't have machinery display full gui. need place type of top-level window such jframe, jdialog, japplet or joptionpane or container displayed in top level window.
then create dialog window , display image in it. simplest joptionpane:
url url = new url("https://maps.googleapis.com/maps/api/streetview?size=600x300&location=46.414382,10.013988"); bufferedimage streetview = imageio.read(url); jlabel label = new jlabel(new imageicon(streetview)); // jpanel panel = new jpanel(); // panel.add(label); // code not needed: // panel.setlocation(0,0); // panel.setvisible(true); // mainguicomponent reference component on main gui // or null if there no main gui. joptionpane.showmessagedialog(mainguicomponent, label);
note pass imageicon jdialog , sufficient too
joptionpane.showmessagedialog(mainguicomponent, myimageicon);
Comments
Post a Comment