aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextField not refreshing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField not refreshing" Watch "JTextField not refreshing" New topic
Author

JTextField not refreshing

Paul Wright
Ranch Hand

Joined: Oct 05, 2004
Posts: 42
I have this bit of code in my application. Its for a sudoku solver. When the user presses the solve button it should write to a JTextField stating that it is "solving" then once solved should rewrite to the same textfield "no errors". The problem I am having is that is it not writing the first solving and regardless of what I try it wont write.

You will see the System.out.prinln() functions. They work and write the exact thing that should be in the jtextfield.

Is there something about actionlisteners or jtextfields im not getting? Maybe something to do with the refresh rate or something....

Any help would be much appreciated.
H Lander
Greenhorn

Joined: Oct 23, 2005
Posts: 15
Originally posted by Paul Wright:
I have this bit of code in my application. Its for a sudoku solver. When the user presses the solve button it should write to a JTextField stating that it is "solving" then once solved should rewrite to the same textfield "no errors". The problem I am having is that is it not writing the first solving and regardless of what I try it wont write.

You will see the System.out.prinln() functions. They work and write the exact thing that should be in the jtextfield.

Is there something about actionlisteners or jtextfields im not getting? Maybe something to do with the refresh rate or something....

Any help would be much appreciated.
H Lander
Greenhorn

Joined: Oct 23, 2005
Posts: 15
The code looks fine to me. I suggest that the problem is somewhere else. There are two possibilities that occur to me:

1) Perhaps your Text Field is not really visible. Try giving is a background color or some text when you first create it so that you can confirm that it is in fact visible.

2) Perhaps somwhow you have two instances of the text field, and the one whose text you are setting is not the one on the screen.

Good luck.
Frank Ertl
Ranch Hand

Joined: Apr 25, 2005
Posts: 59
I assume that the time when "Solving..." is displayed is so short, that you don't see it. Put a line

in you code after displaying "Solving...". This should do.
Paul Wright
Ranch Hand

Joined: Oct 05, 2004
Posts: 42
No i thought that at first but when doing the harder puzzles there is a lag time of about 5 seconds while it is solving(hence the need for the solving indicator) and it doesnt work. It shows all messages but the "solving" at the beginning. It cant print to any other textfield as there arent any.
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 863
    
    1
The problem is you're not giving the event dispatch thread time
to redraw the errorMessage component, since it is busy running
solver.Solve(). When solver.Solve() completes it can redraw it,
but by then it has been set to "No errors" or "Cannot solve".

It should show up if you postpone when the event dispatch thread
calls solver.Solve() by using SwingUtilities.invokeLater(), like
this:

Better would be not to have the event dispatch thread call
solver.Solve(). Run it on a new thread instead, unless it
is doing something that should only be done by the event
dispatch thread.


bitguru blog
Frank Ertl
Ranch Hand

Joined: Apr 25, 2005
Posts: 59
Yes, that's right! My assumption was that the solve()-method starts a new thread, which is obviously no good coding style.
Guess, I'm blind sometimes...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextField not refreshing