views:

95

answers:

3

I've creating a Java Swing application and I realized that I have many many components on a form.

It's not that my interface is cluttered, but nevertheless the total amount can be quite high (hundreds) because the user can enable additional parts of the interface and there have to be list-like repeating panels on the form.

Additionally many components are wrapped into a JXLayer, again increasing the number of visual components.

Until now I couldn't detect any problems besides lagging during scrolling and resizing.

  • Are there any theoretical limits on the number of components? (I doubt it, but I also have to code in VB6, so I've been there...)
  • Are there any pratical limits? At work we have some medium-end workstations which perform fine at first sight, but how does Java/Swing react on low-end workstations or extreme counts of components?
  • Is there any way to profile the GUI of my application besides checking the subjective impression of the user? Are there any objective indicators I can look for (Like total time spent in javax.swing.SwingCoreClassWhichContainsBottleneckCode or something...)
+3  A: 

Only the memory and the underlying OS limits the number of components.

The practical limit is a bit user-subjective. Try splitting the UI into separate tabs or JFrames, this will limit the rendering overhead per screen.

JVisualVM is quite good in profiling java application. You will need to remove the class filters to see the sun* and javax* classes profiled.

kd304
+3  A: 
  1. In theory, you can have as many components as you like.

  2. The practical limit is the amount of RAM. Also, the UI will start to get slow when you have too many components, so performance is an issue, too (as always). Java 6 will help a bit.

  3. Yes. You can create the UI and then force a repaint at the shell level (so everything gets painted) and measure that. Using a profiler should give you some idea which component is especially slow.

Aaron Digulla
+4  A: 

Swing can handle a significant number of components with only memory limitations, particularly using simple components (text box, label, radio button etc). There are some tricks eg reducing the window size and wrapping everything in a JScrollPane, but generally standard techniques such as doing heavy processing in the background will be all you need.

One of the features my company is working on involves a dialog with a repeating JPanel that contains a handful of labels and a button. We tested it on our old Mac Mini (intel core solo with 512mb ram) and creating 500 panels took a few seconds to load but after that scrolling through the panel list or adding new panels was not slow at all.

For serious performance concerns look at JTable which is pretty highly optimised for displaying large amounts of data. It's a little tough to create custom renderers and editors, but not impossible.

Spyder