java - Screenshot of a panel with opened comboboxes -


i have jpanel includes jcombobox. trying take screenshot of panel when jcombobox open. couldn't it. idea?

if run code press alt-p when combo open, see problem.

public class screenshotdemo {     /**      * @param args      */     public static void main(string[] args) {         final jpanel jmainpanel = new jpanel(new borderlayout());          jpanel jp = new jpanel();         jp.add(new jcombobox<string>(new string[] { "item1", "item2", "item3" }));          final jpanel jimage = new jpanel();          jmainpanel.add(jp, borderlayout.west);         jmainpanel.add(jimage, borderlayout.center);          jp.getinputmap(jcomponent.when_in_focused_window).put(keystroke.getkeystroke(keyevent.vk_p, inputevent.alt_down_mask), "screenshot");         jp.getactionmap().put("screenshot", new abstractaction() {              @override             public void actionperformed(actionevent arg0) {                 bufferedimage bf = new bufferedimage(400, 400, bufferedimage.type_int_rgb);                 jmainpanel.paint(bf.getgraphics());                 jimage.getgraphics().drawimage(bf, 0,0,jimage);             }         });          final jframe jf = new jframe();         jf.getcontentpane().add(jmainpanel);         jf.setsize(500, 500);         jf.setvisible(true);     } } 

the dropdown popup window not part of jcombobox's component hierarchy, , therefore not drawn part of it, independently.

a solution take actual screen shot using java.awt.robot:

@override public void actionperformed (actionevent arg0) {      point p = new point(0, 0);     swingutilities.convertpointtoscreen(p, jmainpanel);     rectangle screenbounds = new rectangle(p.x, p.y, jmainpanel.getsize().width, jmainpanel.getsize().height);      try {         robot robot = new robot();         bufferedimage screencapture = robot.createscreencapture(screenbounds);          jimage.getgraphics().drawimage(screencapture, 0, 0, jimage);     } catch (awtexception e) {         e.printstacktrace();     } } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -