javaedt

Why a EDT violation happens?


I started to use CheckThreadViolationRepaintManager to detect EDT violations.

It complains about:

partner = getParameter("partner",generatePartnerSelectionPanel(),Design.partnerSelectionDuration);

Because it does not like generatePartnerSelectionPanel() because it does not like JPanel panel = new JPanel(); in this method. But I cannot find out why there should be a problem around that.

In more details, generatePartnerSelectionPanel() generates a JPanel (I do it not in the EDT) but then, in the getParameter I add the JPanel to the main JFrame and I do it in the EDT (using invokeLater).

So, why there should be a problem?


Solution

  • An EDT violation doesn't mean something necessarily did go wrong, it means you tried to do a GUI related action on a thread other than the EDT (a situation where something might go wrong).

    Creating a new Swing component is covered by "doing something GUI related", hence the warning about the violation.

    This forum has quite a discussion on why it's not recommended to create Swing components on other threads.