• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JTextField not refreshing

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Frank Ertl
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic