Debugging gui events is usually not possible with regular line per line debugging and is done mostly by tracing.
For debugging code that relies on Java swing events like drag and drop, mouse moving, etc., having something similar to code below is very useful:
public boolean isMouseAboveHeaderPanel() { System.out.println("HeaderPanel.isMouseAboveHeaderPanel() called from: " + Thread.currentThread().getStackTrace()[2].getClassName() + "." + Thread.currentThread().getStackTrace()[2].getMethodName()); // ... }
In this way you trace not only current function but also you got information from where you entered that function. Of course to make things easier you should make some kind of a shortcut for entering this trace line. In Eclipse you can do that with code template:
System.out.println("${enclosing_type}.${enclosing_method}() called from: " + Thread.currentThread().getStackTrace()[2].getClassName() + "." + Thread.currentThread().getStackTrace()[2].getMethodName());
This helped me in lot of situations, I hope that it will help you as well.
Leave a Reply