How to create JFrame in the same thread so that it blocks?

前端 未结 2 988
北海茫月
北海茫月 2021-01-17 08:15

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

2条回答
  •  盖世英雄少女心
    2021-01-17 08:59

    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.

提交回复
热议问题