Java tutorial
import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import javax.swing.AbstractAction; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.KeyStroke; public class Main { public static void main(String args[]) { JPanel JMainPanel = new JPanel(new BorderLayout()); JPanel jp = new JPanel(); JComboBox combo = new JComboBox(new String[] { "Item1", "Item2", "Item3" }); JPanel jImage = new JPanel(); JFrame jf = new JFrame(); jp.add(combo); 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) { final BufferedImage bf = new BufferedImage(400, 400, BufferedImage.TYPE_INT_RGB); javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jf.getRootPane().paint(bf.getGraphics()); jImage.getGraphics().drawImage(bf, 0, 0, jImage); } }); } }); jf.getContentPane().add(JMainPanel); jf.setSize(500, 500); jf.setVisible(true); } }