简体   繁体   中英

Optimizing painting of a JFrame with a large number of components in Java

So I have the following problem. I create a JInternalFrame with a VERY LARGE NUMBER of components (lets say 50 000 of text areas). First I do all the logic ( capture all the data which is displayed in the text areas ) and after I set the frame visible, what makes the program freeze ( I suppose it paints all the components).

What would be the best way to optimize the painting ? I guess I should use separate threads so the program wont freeze, but what would be the best approach ? Should I set the frame visible first and then do the login in a thread or should I do all the login and then paint it in a thread ( if so how to paint child components apart from the parent ), or maybe something else ?

Thanks in advance

Swing components may not be used outside of the EDT. So adding threads is not an option. The obvious option is not to have as many components. A UI with 50,000 text areas is unusable. Redesign the UI.

One problem is the layouting on calling pack() . The appropiate LayoutManager and set(Preffered|Minimum|Maximum)Size will help.

It seems you are doing a kind of spread sheet , inside a JScrollPane. In that case a JTable might help, with a virtual model, with text areas on mouse hoover. (A JTable reuses the same component for different cells.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM