Swing "blocking", I think I need to scroll, but I don’t know how much

I have a small java application for efficiently tailing an arbitrary set of files defined in an ini file. My "LogReader" class extends the JFrame and makes a heavy lift; reading a collection of file paths into a vector, and then iterating over the vector, reading each file and adding the last X lines of each to the text areas on the JTabbedPane tabs. The process of creating a vector and iterating over files begins by pressing the JButton button through the ActionListener.

Reading the files worked fine (and still), but the process of reading some 20 files, some of which grow to 30 MB, takes some time. To help get through at this time, I decided to add a progress screen that says: “Now we read file No. 3 of 26: c: \ logs \ superduper1.log”, etc. So I created another "SplashScreen" class, also extending the JFrame and adding a JLabel that will indicate progress. The SplashScreen class has an update () method that simply executes setText () in JLabel.

The ActionListener in JButton calls RefreshLogs (), which looks something like this:

vctFileStrings.clear();
tpMain.removeAll();
frmSplash.update("Loading Configuration"); //Update the label on the Splash Screen instance
BuildVectorOfLogs(strConfFile); //Read the collection of files into the vector
frmSplash.update("Reading Logs");
ReadLogs(); //read the files, updating the Splash Screen as we go

and then ReadLogs () iterates over the vector, reading the files and creating the TabbedPane.

, , RefreshLogs() ActionListener, Splash Screen . , RefreshLogs() , , ( ). , , , .

:
- ? , , ActionListener?
- , ? - ? GUI ( ) , JButton?

+3
3

: , . Thread Dispatch Thread, , , , .

SwingWorker. (, ) , EDT. SwingWorker . , , - .

Sun SwingWorker.

+4

, . (EDT), , .

SwingWorker . Swing Worker Thread, , .

+3

, , , , NetBeans NetBeans, - Java Desktop. , , "". Action API, .

, .

0
source

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


All Articles