Java Swing How to - Dump Thread Stack Trace








Question

We would like to know how to dump Thread Stack Trace.

Answer

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//from w w  w  .j  a  v  a  2  s  .  com
import javax.swing.JComboBox;

public class Main {
  public static void main(String[] args) {
    JComboBox<String> emptyBox = new JComboBox<String>();
    emptyBox.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        Thread.dumpStack();
      }
    });
    emptyBox.addItem("test");
  }
}