4

I have java applet with JTable. Due to lots of data and poor network bandwidth it takes lots of time to perform any operation like load the table or change it. I'm thinking about adding sort of activity indicator to let user know that his request is processing. Before i use JProgressBar, I'd like to know whether there are other options like ajax activity flower.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Misha
  • 5,260
  • 6
  • 35
  • 63

3 Answers3

4

The easiest way would be setting a (not animated) WAIT_CURSOR

// Setting cursor for any Component:
  component.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
  doProcessing();
  component.setCursor(Cursor.getDefaultCursor());

see http://www.catalysoft.com/articles/busyCursor.html

For an animated cursor see:

http://book.javanb.com/swing-hacks/swinghacks-chp-12-sect-2.html

stacker
  • 68,052
  • 28
  • 140
  • 210
  • That's enough for me even though previous answers are awesome also. However i see strange behaviour, on one part of my applet the cursor is in wait state and on another is regular. Can i make it be the same state for all components of the applet? – Misha Aug 18 '11 at 11:46
  • @Mike: If the two regions share a common `Container`, [`setCursor()`](http://download.oracle.com/javase/6/docs/api/java/awt/Component.html#setCursor%28java.awt.Cursor%29) should work over "subcomponents, except for those that have a non-null cursor." – trashgod Aug 18 '11 at 14:39
3

SwingWorker was designed for this, as suggested in this example. In particular, "Note that it safe to mutate the tableModel from inside the process method because it is invoked on the Event Dispatch Thread."—publish()

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
3

You can use JBusyComponent for this. Just wrap your Table or the Scrollpane in the JBusyComponent. But remember to load the data outside the event dispatch thread. For this you can use the SwingWorker as suggested in the other answer. JBusyComponent already provides a BusySwingWorker for this.

Tobias Schulte
  • 3,765
  • 1
  • 29
  • 33