0

I have a swing application with 5 jTextFields.

there is a button to call a "calculate" method but for user convenience sake i want to have the application constantly attempt to calculate the answer (run a method) whenever the user types a new number / changes any number in any of the textfields. So far I have 5 different KeyTyped Events (one for each jtextfield) in which i call the method.

However I have a problem and that is when i launch the application this will not work for about 10 seconds - the method will just not run. After about 10 seconds it works nicely.

How can I a) get rid of this 10 second lag or b) display a dialog like "loading application" until it is ready?

Or maybe another way because what I did is horribly wrong?

here is the source: here

i only included this new "feature" in the LumpSum main window that comes up when you start the application.

Killerpixler
  • 4,200
  • 11
  • 42
  • 82
  • 1
    For better help sooner, post an [SSCCE](http://sscce.org/). – Andrew Thompson Apr 09 '13 at 13:41
  • 2
    1) With the current information, we cannot determine where that 10 second lag comes from. 2) Use a `DocumentListener` iso a `KeyListener` when dealing with `JTextComponent` instances 3) You can show a "Loading application" dialog but only if you do your work on a worker thread. See the [Swing concurrency tutorial](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) – Robin Apr 09 '13 at 13:42
  • i put a link to the source – Killerpixler Apr 09 '13 at 14:03
  • 2
    You shouldn't include a link to the source. You should strip down your source into an SSCCE, and post that here (as @AndrewThompson already suggested) – Robin Apr 09 '13 at 14:29

1 Answers1

1

This example uses both a FocusListener, to catch Tab key navigation events, and a PropertyChangeListener, to catch editing events within a JFormattedTextField:

image

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    `Converter`, cited [here](http://stackoverflow.com/a/3072979/230513), is an alternative that uses `EventListenerList`. – trashgod Apr 09 '13 at 16:03