Debugging GUI events

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.


Posted

in

,

by

Tags:

Comments

One response to “Debugging GUI events”

  1. Marjan Panic Avatar

    In the most complex cases, debugging GUI should happen by using some log files and/or consoles as debugging line per line is not valid due to the fact that what you are debugging is influenced by end user actions (which should not be part of your debugging)

    There for, I strongly recommend using some 3rd party logger tool and/or developing your own!

    Good luck

Leave a Reply

Your email address will not be published. Required fields are marked *