Search |
||
Debugging Swing - is it really difficult ?Posted by alexfromsun on November 23, 2005 at 1:57 AM PST
Every experienced Swing developer knows that Swing components must be accessed from Event Dispatch Thread (EDT) only. Working with JComponents from any other thread may lead to unpredictable result. Consider the following code: import javax.swing.*; import java.awt.*; Running this code I get the desirable unselected JEdiorPane, ... sometimes
Sometimes I get it like this:
Working with Swing not from EDT, you might see your components and layouts distorted or not reflected the current state. Actually the main rule is It's been so many articles like this and this, so I suppose that most of Swing programmers know how it works and do the right thing. Our previous example might be fixed this way: public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createGui();
}
});
}Pretty easy, right? The fact that every JComponent's listener is automatically invoked on EDT makes it even more easy. In my opinion, understanding that Swing is a single-threaded library is not difficult Funny thing, I took part in interviewing several java programmers who claimed to know Swing well, but at the same time some of them had no idea what EDT is. That's why I am really interested in your opinion, Set of questions
Any comments would be appreciated! I also posted new topic to javadesktop forum Thanks »
Related Topics >>
Swing Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|