Mam JPanel
, który zawiera . Próbuję zrobić zrzut ekranu tego panelu po otwarciu JComboBox
. Ale nie mogłem tego zrobić. Dowolny pomysł?Zrzut ekranu panelu z otwartymi comboboxami
Jeśli uruchomisz ten kod, naciśnij Alt-P kiedy kombi jest otwarte, zobaczysz 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);
}
}
tak to jest problem Spędziłem godziny, ważne pytanie. – benchpresser