Confusion between whether the code should execute EDT (Event Dispatch Thread) or not?

I developed a Swing GUI that contains 12 JPanels. Initially, all the code JPanelwas written in the main code of the class JFrame. As a result, the code became too long (more than 10,000 lines).

Now I want to reorganize the code in order to break the code into 13 classes (12 classes for one JPaneland 1 class for the main one JFrame) instead of 1 class carrying all the code.

But I have some confusion, which are as follows:

  • Initially, those 12 JPanelwere installed on the "Map" JPanel, and the layout of the "Card" JPanelwas set to CardLayout, so only 1 JPanelof the 12 is JPanelshown based on the button that the button is clicked on. Now that I have divided those 12 JPanelinto MainJFormand implemented each of them into my own class, it seems to me that I need to create an instance JPanelwhen the user clicks the button. So, it would be better to do this heavy task on EDT (Event Dispath Thread). If not, will this work to instantiate the JPanel stream SwingWorkerand pass the ref link. to EDT?
+3
source share
4

, , . , , 12 . , , .

, , , , , , (ui ).

, , , swingworker , , . . , , , ui (, ) EDT.

+1

12 JPanel EDT . . . . , .

0

, EDT. . Java: Swing Is it safe to create Swing / AWT NOT widgets in a Dispatch Thread theme? .

If (as part of their initialization) any of these panels requires something that can take a lot of time (for example, disk or network access), these calls should be delegated to another thread, but not any changes to the swing of the component itself.

0
source

You can watch any SwingSet demo such as SwingSet2 or SwingSet3 .

0
source

Source: https://habr.com/ru/post/1729684/


All Articles