Reputation: 61
Hello? anyone had a problem like: cursor blinking in more than one field at a time? In my case the following happens: When you double click on a field JTextField, opens a JDialog, so after closing this, the focus is directed back to the field clicked before opening the screen.
What happens is that after performing this action, two fields are flashing at the same time (usually the first field screen, as well as the field in which efetuei double click). This medium is random, there are cases in which it does not occur.
When debugging the inner class Handler, contained within the class DefaultCaret more specifically the actionPerformed method, realized that: time is a field, and time is another, which are precisely the fields that are flashing (q seems obvious I know). but they are the own inner classes of Java that are calling the method.
When passing over the field using the Tab, the cursor false, vanishes.
I'm using JDK 6
I returned the focus within the invokeLater(), but not solved. Now both synchronized flash
The first JComponent focusable is one of the fields that flashing improperly
I'm using my own FocusTraversalPolicy, does that may be influencing? The funny thing is that there is no treatment particularly strange about my class.
I noticed that the standard Java class, using a method within the Syncronized getFirstComponent(), but added the same control, but still is not ok
Upvotes: 1
Views: 925
Reputation: 61
This situation occurs because the project I'm developing is quite large, so do not get small examples of implementation
The project has many components, Tables and Container's, which require focus through at the same time.
It turns out that Swing, put in a queue for execution, a lot of threads, and then dispatching them going, and while he did not finish running it, you can cram grabFocus() or requestFocus(), which does not cry, the first he has to finish everything and then run my request focus.
Resolved palliatively this situation, using the Swing SwingUtilities.invokeLater(...);
Thanks for the tips.
Upvotes: 0
Reputation: 57421
Actually it's Focus issue for me.
Normally when JTextComponent
looses Focus setCaretVisible(false)
/ setSelectionVisible(false)
is called and when Focus gained opposite thing happens.
After closing JDialog
try to return Focus inside invokeLater()
. Also check what's the first focusable JComponent
in the JDialog
's parent.
Upvotes: 5