For debug purposes, I need to draw image on the screen in a simple window.
Swing handles all it\'s events in a separate message loop thread. That means that if I do
How to create JFrame in the same thread so that it blocks?
Use a modal JDialog.
JOptionPane.showMessageDialog(null, scrollPane, message, javax.swing.JOptionPane.INFORMATION_MESSAGE);
This has a flaw though - you can't see the debug window on the taskbar.
Don't use null for the dialog owner. Make sure you specify the owner JFrame. Whenever you click on the taskbar icon the frame and child dialog will both show up.
Build your GUI outside the loop once and then use
// read new component data
screenshot = MSWindow.screenshot();
// modify components
label = new JLabel(new ImageIcon(screenshot));
// force the frame to repaint its chilfren
frame.revalidate();
frame.pack();
to "refresh" it inside the loop.