Focus events being received out of order

I have a complicated applet where each component is registered with multiple focus listeners. I have several pairs of JTextFields and JButtons - textfield A, button A, textfield B, button B etc. Clicking on a JButton normally causes a JTable to be popped and focus transferred to it. Clicking on the table header or selecting a table row causes the table popup to close and the focus transferred to the textfield associated with the button.
I'm running into a strange case where the focus is initially on textfield A. Clicking on button B causes a temporary loss of focus on textfield A. The trace shows that the focus owner is null and the permanent focus owner is textfield A. The table still gets launched. Selecting a table row causes it to close but no component has focus any more. Focus owner continues to be null, and permanent owner continues to be textfield A.
After working on other windows in the meantime, and returning to this window I find that the focus in now back to textfield B, as it should. However, the trace shows that B has received permanent focus events. This is followed by receiving permanent focusLost events on A and then permanent focusGained events on A. At the point all in said and done, the focus appears on B.
Does someone know why the focusGained event on B appears before focus events on A? Another strange thing in the trace was that some focus gain/loss method invocations were interrupted, another focus method invoked and the previous method resumed. I could possibly take care of this by using synchronized on all focus gain/loss methods. Also, some methods show only part of execution and not even resumed. This is still a mystery to me. I'll appreciate if someone can shed light on this.

One of the things you'll notice is that when a text field loses focus to a right-click JPopupMenu, it is never just one foucs lost/gained pair, but rather they trade focus back and fourth a few times. This is the same when the popup closes, the focus trades back and fourth a few times.
You are describing a similar situation between a button and a text field.
There never was any guarantee the gained/lost events happen in any order. Also, if there is a chain of focus events, the information in the intermediate events may not be useful.
If you really do need to understand the focus changes at an actionable level, you might want to consider writing a focus helper class that can be used to answer semantic questions about focus changes, such as, did this component lose focus because of a button click? Or was it a Popup? Or was it a Tab-keystroke?
The focus helper can store 'hidden' information in any JComponent using JComponent.setClientProperty(Object key, Object value)...
So instead of creating a focus listener like:
myComponent.addFocusListener(new FocusAdapter() {
  public void focusGained(FocusEvent e) {
    // do stuff here
});You can do it like this:
myComponent.addFocusListener(FocusHelper.createTextFieldToButtonListener());and in that method it creates the listener like this (you might need to pass some parameters):
public static FocusListener createTextFieldToButtonListener() {
FocusAdapter adapter = new FocusAdapter() {
  public void focusGained(FocusEvent e) {
    recordEvent(e);
    // do stuff here
return adapter;
}The helper method "recordEvent" tags those components with additional information about permenant and temporary focus ownership. Also it clears hidden information that is no longer useful.
Then later on you can give the focus helper a FocusEvent, and ask it, is this text field gaining focus because of a Tab-In, or is it because of a popup menu has closed?
The helper constructs answers based on the hidden properties it finds in the e.getOppositeComponent() and e.getSource(). It put those properties there, so it knows what they mean, and it uses them to distinguish between useless information in the focus event chain, and the important things you want to know.

Similar Messages

  • Why is the track order of my album being played out of order?

    The track order of my album appears correct in iTunes and on my iPod Classic 160 but.......... it plays the tracks out of order. frustrating when listening to stand up comedies.... I checked the "info" of each album and the track listing/order is correct..... help?

    Have you checked your iPod's Settings to make sure the Shuffle setting is set to Off.
    B-rock

  • My texts are being sent out of order

    Hello I just got my galaxy s4 and whenever I text my boyfriend (who has another carrier) and its a long text it would be out of order. The last 2 sentences would get to him first then the beginning of the conversation will show up last....
    Anyway to fix this? He has virgin mobile if that helps....

        That's a strange issue 1631705, but we'll be happy to figure this out. Does this only happen with your boyfriend? Have you tried long messages to other people? If it is only happening with him, it may be the way Virgin mobile process enhanced messages (over 160 characters).
    MarquiaF_VZW
    Follow us on twitter @VZWSupport

  • Prints received out of order

    Is it normal to have Apple ship your printed photos (4x6's) in a different order than what you sent them from iPhoto as? I spent some time carefully arranging the photos in my album so that when I received the printed photos they would already be in order, ready for inserting into my photo album - alas, when I received the photos they were in completely random order, and not even date/time information anywhere to help me, not even on the index print! I had to spend just as much time arranging the photos in chronological order using my iPhoto display as a guide - it was time-consuming and frustrating! Is this to be expected when ordering prints from Apple, or should I make a complaint/comment?
    Flint

    I'm guessing that the uploaded files were arranged by the default alphanumerical order that the Finder uses. For future orders you need to arrange them in the order you want, batch rename them sequentially and then export to the desktop using the Use Title Option. Then, you need to manually add a zero to the first nine photos, -1 to -01, etc., so they will be listed in the correct order. Those are the files you'll need to upload for printing. Yes, it's a lot of extra work.
    OT

  • IPhoto 9.3 - all EVENTS out of order, random key photos, some empty.

    Since iPhoto 9.3 update, all Events folders at top of Source List are showing correctly as thumbnails - correct order (manual), key photos - no probs. But they're also further down the S'List, under another EVENTS, this time out of order. When I go to full screen view to access ALBUMS thumbnails, the Events are above them, looking like Albums (stack of white framed photos), in random order, with random key photos, and some are empty. Also, on this view only, scrolling is not working properly.

    I have had the same problem... not to mention I made it worse trying to reset my manual settings for iphoto!!!!
    Now all of my stuff on my comupter is out of order!! : ( It will take me months to fix this. I often use iphoto on my ipad for work and it looks like that is not going to happen now!
    I am very unhappy about this apple people!
    DPM

  • Out of order photos

    I'm trying to synch my photos from iphone 3GS to my new macbook pro, but the photos are completely out of order, are all contained as one event, with the date being the date of the synch,  and there is no recognition of duplicates.  It transfers all 1200 pictures as one event! All out of order! I never had this problem with my old macbook pro, and just bought this new one, with Snow Leopard 10.6.8.  Any suggestions?

    I now downloaded the latest iphone software update, and the photos are appearing in order, but still as one huge event, with no recognition by iphoto that 99% of these are duplicates.

  • Files out of order in Camera RAW

    When I try to load a batch of .tif files into photoshop Camera RAW, they end up being all out of order numerically when in Cam RAW. How can this be resolved?

    I think the only chance you have to keep your manual order, is to use Bridge, put the images on the order you want them to be opened, and select not the 'Open' neither 'Open with'. Select 'Open In Cameraraw'

  • CQLServerTrace : out of order timestamp Error

    Hi everyone,
    When I try to run this command I am getting the error which I specified bottom, how can I solve this problem?
    is-total-order parameter was set to "True".
    This is a simple Helloworld Application
    channel parameters are default ( max threads and max size was set to 0
    11.1.1.7 Version
            SELECT
                           shortName, avg(price) as price
                      FROM
                           stockInputChannel [PARTITION BY shortName ROWS 3 RANGE 3 SLIDE 3]
                      GROUP BY
                           shortName
    <Apr 28, 2013 1:15:48 PM VET> <Emergency> <CQLServerTrace> <BEA-000000> <event timestamp is out of order timestamp0=1,367,171,106,000,000,000 timestamp1=1,367,171,103,357,000,000 event=22715375 : kind=E_PLUS tuple=Tuple(14886,25458514) 'obj=Stock21921411,3.3803851379397982,char[15]=FWGUKXDXBPSYGPB,1367171103357,char[5]=XTCFZ,1367171103357000000,byte[1],obj=PartitionNode25458617,' ts=1367171103357000000 totalOrderingGuarantee=true in PO_GROUP_AGGR#144
    oracle.cep.execution.SoftExecException: event timestamp is out of order timestamp0=1,367,171,106,000,000,000 timestamp1=1,367,171,103,357,000,000 event=22715375 : kind=E_PLUS tuple=Tuple(14886,25458514) 'obj=Stock21921411,3.3803851379397982,char[15]=FWGUKXDXBPSYGPB,1367171103357,char[5]=XTCFZ,1367171103357000000,byte[1],obj=PartitionNode25458617,' ts=1367171103357000000 totalOrderingGuarantee=true in PO_GROUP_AGGR#144
            at oracle.cep.execution.ExecException.OutOfOrderException(ExecException.java:154)
            at oracle.cep.execution.operators.GroupAggr.run(GroupAggr.java:780)
            at oracle.cep.execution.operators.ExecOpt.run(ExecOpt.java:1002)
            at oracle.cep.execution.operators.ExecOpt.run(ExecOpt.java:984)
            at oracle.cep.execution.operators.ExecOpt.run(ExecOpt.java:1062)

    Hi,
    I am using Oracle CEP 11.1.1.4.
    I am trying to understand pattern matchin feature therefore my examples are meaningless. I am producing data like that ( between 1-3 and printing to console ):
    00:00:00 Producer produced 1
    00:00:05 Producer produced 2
    00:00:10 Producer produced 1
    00:00:15 Producer produced 3
    00:00:20 Producer produced 3
    00:00:25 Producer produced 1
    Then I am looking for the data ( or you can think that as 1-2-3 ) that has been produced once and has not been produced within last 10 seconds.
    I am using system-timestamp channels.

  • Photos not synced correctly to iphone... Unorganized and out of order

    After syncing my Iphone 4s with my macbook pro, all of my "Event" photos are out of order. If I open a specific event there will be photos that do not belong there and have no relation to that event... Same with the "faces" feature... I will specifically look for all pictures with "Mary's" face and majority of the pictures are other people with "Mary" not even in those pictures...
    I have looked at my macbook and all of the photos seem to be correct on that and in the right locations... Not sure how to fix this problem or what to do :-/
    This is a feature that I use constantly and would appreciate if someone could help guide me to correcting it....

    Hi Tasha48323,
    If you are having issues with unusual or incorrect data after a recent sync with iTunes, you may want to turn off the sync options for Photos, click Apply (this should clear that data off the iPhone), then turn Photo syncing back on and Apply again (which should resync all the data back). You may find the Resolution section of the following article helpful (the article primarily concerns a slightly different issue, but the steps are the same):
    iOS: "Not enough free space" alert when trying to sync
    http://support.apple.com/kb/ts1503
    Regards,
    - Brenden

  • After upgrading to iOS8, iPhoto Events from my Mac are out of order.

    After upgrading to iOS 8, iPhoto Events from my Mac are out of order on my & my husband's iPads and iPhones.  Anyway to get back in order or do we need to revert to prior iOS?

    iPhoto for iOS is no longer supported nor works in iOS 8 and has been dropped from further development by Apple.  This Apple document describes how to migrate photos from iPhoto to Photos: Migrating from iPhoto for iOS to Photos on iOS 8
    It's a whole new ballgame now.  Here's some info on how the Photos apps now works.
    Your photos are still on your phone.  With iOS 8 there is no My Photo Stream or Camera Roll any more.  The MPS has been replaced with the Recent Activity album.
    The CR is replaced by the Collections mode.  The closest we can get to the Camera Roll is to turn off the Summarize Photos feature in the Settings/Photos & Camera pane and view the photos in the Collections/Moments window.
    The photos will be in chronological order when scrolled up from the bottom of the window.
    The Recent Activity album is showing the photos added in the last 30 days going back to 8/20 (today being 9/18).  In iPhoto on a Mac the My Photo Stream is showing more like 31 days, 8/19 to today, 8/20. It must be how the two devices calculate the last 30 days.
    WARNING:  If you use iTunes to sync photos between your iPhone or iPad and your Mac do not activate the iCloud Drive. Doing so will kill the capability of using iTunes to sync with your mobile device and disable Documents & Data syncing for your iCloud account on OS X Mavericks and earlier Macs, as well as iOS 7 and earlier devices.

  • Imovie events out of order

    Since ive upgraded to imovie  in Maverick all of my events are not in order according to dates the clips were taken.  They all out of order. is there an easy way to have the events in order according to date the video clips were taken?

    Unfortunately this appears to be a bug in 10.0. See https://discussions.apple.com/thread/5468703?tstart=0

  • I've just imported photos that are misdated and appear out of order in my events. How can I correct the dates on these events so they appear properly?

    I've just imported photos that are misdated and appear out of order in my events. How can I correct the dates on these events so they appear properly?

    The one iin the Photos ➙ Adjust Date and Time menu option:
    checkbox below:

  • Iphoto question. I have 8 images in an event. One is out of order. I have tried to copy and paste, and to drag and drop, but I cannot get it to move. Can anyone help?

    I have an iphoto question. I have 8 images in an event. One is out of order. I have tried to copy and paste, and  i have tried to drag and drop, but it won't move. Any help?

    IPhoto forum:
    https://discussions.apple.com/community/ilife/iphoto

  • When downloading from my PD 150 to the event window in my iMac the clips are out of order and split into many subclips   ac  iMac the clips in the

    when downloading from my PD 150 to the event window in my iMovie the clips are out of order and split into many subclips. Very frustrating

    Nevermind, somehow it's magically back in order.

  • Receiving emails out of order

    I am receiving emails out of order as of yesterday. How do I fix this?

    Assuming you are using Mail, perhaps one of the 'Sort by' options has got messed up.
    In Mail go to View>Sort by and have a look at the options to see if something needs changing.

Maybe you are looking for

  • Getting Error - Dimension has multiple leaf levels which are not identical

    Hi All, While creating two hierarchies with in same dimension , i am getting error like - Dimension has multiple leaf levels which are not identical. Does this error mean , the number of levels in both hierarchies should be same or it has some thing

  • IPhone App Cannot Be Opened?

    http://www.gabejacobsblog.com/iphone-app-cannot-be-opened Click the link to look at the screenshots. I don't have any idea why this happened, but basically when I open Tap Tap Revenge it gives me an error saying "tap tap cannot be opened" So weird! A

  • TA24770 How can I reset the "Open With" menu?

    Any help?

  • Transfering files in ASCII mode using SFTP

    Hi All, We are using SFTP to transfer our files since we are using VPN. But we need a file to be transfered in ASCII mode from the remote system. We are using toad for that, but i heard that SFTP transfers file only in Binary mode by default. Is ther

  • By using OID how to unzip the folder and load bunch of .csv files

    Hi All bellow is the my scenario. in my scenarion we have created FTP folder that will load the .zip files(Every Day). .zip files that will contain bunch of .csv file (flat files) and by using OID need to extract the .zip file and load the all .csv f