मेरे पास JPanel
है जिसमें JComboBox
शामिल है। मैं इस पैनल का स्क्रीनशॉट लेने की कोशिश कर रहा हूं जब JComboBox
खुला है। लेकिन मैं यह नहीं कर सका। कोई उपाय?खोले गए comboboxes के साथ एक पैनल का स्क्रीनशॉट
यदि आप इस कोड को चलाते हैं तो Alt-P दबाएं जब कॉम्बो खुला है, तो आप समस्या देखेंगे।
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);
}
}
है हाँ यह एक समस्या मैं बिताया है घंटे, एक महत्वपूर्ण सवाल है। – benchpresser