开发者

Is this GUI threadsafe (Using Swing)?

开发者 https://www.devze.com 2023-03-02 23:59 出处:网络
I have the following code in my constructor for my GUI search.addActionListener(new ActionListener() {

I have the following code in my constructor for my GUI

    search.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //do stuff
       }});

The problem was that when I the "//do stuff" runs, it takes a while, and it doesn't let me do anything else. So I made "//do stuff" into a thread, and i开发者_如何学Pythont runs, and I can do other stuff in the GUI at the same time. I wasn't sure if this was threadsafe or not, and if not, how to fix the problem.


The problem is that you were probably blocking the main Swing event thread (the thread that handles things like button clicks). You can read up about it (and one possible solution) on Swing Worker Threads

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号