简体   繁体   中英

Java Swing button stays pressed

I have a java button that creates a thread, but the button stays pressed even after the thread finished doing the job.

public class MainFrame extends javax.swing.JFrame {

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        Thread t = new Thread(new Calculus());
        t.start();
    }
}

public class Calculus implements Runnable {
    @Override
    public void run() {
    //do stuf
    }
}

Am I implementing Runnable in the wrong way? Or does the thread need something to finish?

That is the way a JToggleButton works. Just use a JButton for a normal Swing button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM