JTextfield:  Changing focus, then doing stuff

So I have 3 JTextFields that are essentially "connected" (I automate tabbing and such back and forth). I have no problem gaining focus, whether it be transferFocusBackward(), or whatever else. My problem is when getting the focus I cannot do anything with it like taking the letter the user typed and insert it into the next field.
My code that I used is in KeyTyped and I do a
JTextField fake = new JTextField();
fake.transferFocus();
JTextField newFocus = ((JTextField)KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
newFocus.setText(String.valueOf(event.getKeyChar))
When I check to see who the focus is on before and after I call transferFocus(), it doesn't change JTextFields (I know because I name them differently and ask their names). Does someone know a better way...that actually changes focus, when it is called, or have any workarounds?

Nevermind I figured a workaround for it. I set the setFocusCycleRoot to true in the constructor, and then said
JTextField fake = new JTextField();
JTextField newFocus = ((JTextField)this.getFocusTraversalPolicy().getComponentBefore(this, fake));
//I stuck what the user typed at the beginning of the text field...not really sure which is the better way
newFocus.setText(event.getKeyChar()+newFocus.getText());
fake.transferFocus();
The reason it wasn't working is because swing hadn't actually acknowledged that the focus had changed yet...apparently this happens later.
The reason I had asked was that there was an edge case on the three JTextField, lets say the user types something into the first text field and moves to the next field, then randomly goes back, well, when they press a letter, then they would just jump to the next JTextField, and the letter wouldn't appear...i think that would be more confusing than having the letter appear in the next text field, but meh, we'll see.

Similar Messages

  • Am I correct that Photos does not support external editors? i.e., in Aperture, I click Photos Edit with.... and can open in Photoshop or various plug-ins. Changes are then automatically saved back to Aperture. Nonexistent in Photos?

    Am I correct that Photos does not support external editors? i.e., in Aperture, I click Photos > Edit with.... and can open in Photoshop or various plug-ins. Changes are then automatically saved back to Aperture. Nonexistent in Photos?

    Thanks Larry. That certainly gives me some understanding. Can't imagine I'm the only Aperture user with that concern, so I certainly hope Adobe and others will fill the void. Without that feature, Photos is pretty much a non-started for me.

  • Accelerators, JTextField, and focus

    I created a JMenuItem for Save. I also created an accelerator for the Save menu item.
    JMenuItem saveItem;
    JMenu fileMenu = new JMenu ("File");
    fileMenu.add (saveItem = new JMenuItem ("Save"));
    saveItem.setMnemonic ('S');
    KeyStroke cntrlS = KeyStroke.getKeyStroke(KeyEvent.VK_S,
    Event.CTRL_MASK);
    saveItem.setAccelerator (cntrlS);
    saveItem.addActionListener (new ActionListener() {
    public void actionPerformed (ActionEvent e) {
    doSaveNote();
    When the user is finished entering data into the JTextField(s), the user then either presses ctrl-S or clicks on the Save button on the menu. My code (not shown) validates data in JTextFields when the Save accelerator or button is pressed (blank field is considered invalid as well as wrong flight number). If data is invalid, then the first field with invalid data gets focus.
    If the JTextField has focus and invalid data is there, then when the user clicks the Save button the JTextField still has focus with a message letting the user know the data is invalid. However, if the user puts invalid data in the JTextField and uses the accelerator ctrl-S without tabbing out of the field first, the invalid JTextField does not get focus and no error message is presented. When using the accelerator the invalid JTextField only gets focus and prints an error message if the user tabs out of the JTextField befor pressing ctrl-S.
    I don't want to tab out of the field. Why is the behavior different between the accelerator and clicking the Save button? Any help is appreciated.

    You can request focus for another component.
    Or you could do: myTextField.setFocusable(false). But in this case you would have to make it fosucable later on if you want to use it.

  • Key-changing focus in JLists

    Consider the following JList -
    String[] testData = {"one", "two", "three", "four", "five"};
    JList testList = new JList(testData);When testList has focus, pressing 't' will cause the selection to traverse between items beginning with 't'. This also happens when pressing 'f' or 'o', although the behaviour is somewhat inconsistent in all cases (e.g. it doesn't work all of the time).
    How to disable this behaviour? The API documentation makes no mention of it, so I assume that it is specific to PLAFs (I use Metal by default). The only solution I have found to work thus far is to invoke the following after JList initialisation -
    EventListener[] listeners = testList.getListeners(java.awt.event.KeyListener.class);
    for(int j=0; j<listeners.length; j++) {
      testList.removeKeyListener((java.awt.event.KeyListener) listeners[j]);
    }However, this seems like an absurdly heavy weight solution to such a silly problem. Is there a getter/setter I've not seen? I've already tried tinkering with InputMaps and ActionMaps, but they don't seem to have an effect.
    Cheers,
    Damien.

    I tried using the div tag and changing focus to an transparent screen so that it is seamless to the user.
    That does not work too. When you change focus by burring and then focus on the transparent screen the cursor acts wierd and remain in wait state all the time.
    Any idea what am I doing wrong here?
    V I

  • Clicking on "order prints" just says "connecting" then does nothing ...

    I fear that I screwed up somewhere in setting up my 1-click setting and now when I select a photo and click on order prints, it just says connecting then does nothing. It doesn't even take me to the 1-click screen to allow me to change account info. Does anyone know of a way to at least get me back to the 1-click page to allow me to associate my mac account to iphoto?

    Hi bplatinum,
    http://docs.info.apple.com/article.html?artnum=303168
    This Apple kb says to reinstall iPhoto 6. Hopefully that will solve it for you.

  • Sync message, "You have changed the settings for your iphone.  Would you like to apply these changes?" What does this mean?  I don't recall changing anything...

    Sync message, "You have changed the settings for your iphone.  Would you like to apply these changes?" What does this mean?  I don't recall changing anything...

    The main settings that are changed in these cases can be found in this article:
    http://support.apple.com/kb/ht1386
    To ensure you don't lose any data you don't want taken off, ensure that each Summary, Apps, Music, Movies, TV Shows, Podcasts, iTunes U, Books, & Photos have the settings you would prefer on the computer. 
    If anything gets changed on any of those pages, you will be prompted with that message.  If they look fine, especially after adding some media like songs or videos, then you can apply the changes without fear.

  • Change Focus to Other Application?

    Hi
    I would like to know if there is some way to change the focus to other applications without using Robot to manually change the focus (like the user would do) or using native methods.
    This is because one of my friends has a problem with a program that keeps taking the focus. An application can then be used to bring the focus back to the program he was currently using.
    It would be nice if there was methods for this in standard Java so we don't have to use native methods, and it would be quite a cumbersome to use Robot)
    (I have searched for it, but the only help I could find so far was about changing focus between components within your own application)

    Yes. That is what I wrote, but isn't there a smart way to do it, like using excisting classes to change focus between applications? - Maybe a class which can also iconify the other applications or such?
    I doubt it exists since it would be hard to make platform independant, but I think it's worth to look for.

  • My iPad does not recognize my Apple ID. I have reset several times (as requested) it's stated that its successful, and then does not work..I cannot access anything!!!!

    My iPad does not recognize my Apple ID. I have completed a reset several times (as requested).
    The re-set is shown as successful but then doesn't work..I'm locked out of everything!!!

    To change the iCloud ID you have to go to Settings>iCloud, tap Delete Account, provide the password for the old ID when prompted to turn off Find My iDevice, then sign back in with the ID you wish to use.  When you do this you may find that the password for your old ID isn't accepted.  If this should happen, and if your old ID is an earlier version of your current ID, you need to temporarily recreate your old ID by going to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Click edit next to the primary email account, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iDevice on your device, even though it prompts you for the password for your old account ID. Then save any photo stream photos that you wish to keep to your camera roll.  When finished go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https://appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • After closing Firefox to use IE8 or any other program, everything is very choppy and slow. I have to go into Taskbar, Processes, and close firefox.exe manually (which is using up all the memory/CPU). Then, and only then, does everything behave normally. W

    After closing Firefox to use IE8 or any other program (like InterVideo to watch a DVD), everything is very choppy and slow. I have to go into Taskbar, Processes, and close firefox.exe manually (which is using up all the memory/CPU and should have closed before). Then, and only then, does everything behave normally. What is going on and what am I doing wrong or missing??
    == This happened ==
    Every time Firefox opened
    == about a couple months ago and happens every time I close Firefox.

    <u>'''Kill Application'''</u>
    In Task Manager, does firefox.exe show in the <u>'''Processes'''</u> tab?
    See: '''[http://kb.mozillazine.org/Kill_application Kill Application]'''
    '''<u>Causes and solutions for Firefox hanging at exit:</u>'''
    '''[[Firefox hangs]]'''
    '''[http://kb.mozillazine.org/Firefox_hangs#Hang_at_exit Firefox hangs at exit (Mozillazine article)]'''
    '''[[Firefox is already running but is not responding]]'''
    <u>'''Safe Mode'''</u>
    You may need to use '''[[Safe Mode]]''' (click on "Safe Mode" and read) to localize the problem. Firefox SafeMode is a diagnostic mode that disables extensions and some other features of Firefox. If you are using a theme, switch to the DEFAULT theme: Tools > Add-ons > Themes before starting Safe Mode. When entering Safe Mode, do not check any items on the entry window, just click "Continue in Safe Mode". Test to see if the problem you are experiencing is corrected.
    See:
    '''[[Troubleshooting extensions and themes]]'''
    '''[[Troubleshooting plugins]]'''
    '''[[Basic Troubleshooting]]'''
    If the problem does not occur in Safe-mode then disable all of your extensions and then try to find which is causing it by enabling one at a time until the problem reappears. You have to close and restart Firefox after each change via File > Restart Firefox (on Mac: Firefox > Quit). You can use "Disable all add-ons" on the Safe mode start window.
    <u>'''''Other Issues''''': to correct security/stability issues</u>
    <u>'''Update Java'''</u>: your ver. 1.6.0.19; current ver. 1.6.0.20 (<u>important security update 04-15-2010</u>)
    ''(Windows users: Do the manual update; very easy.)''
    See: '''[http://support.mozilla.com/en-US/kb/Using+the+Java+plugin+with+Firefox#Updates Updating Java]'''
    Do the update with Firefox closed.

  • Changing defaultTextFormat then setting htmlText changes defaultTextFormat back?

    Hello,
    So I make an instance of a display object defined in an external .swf that has a TextField. I set that TextField to a new format using setTextFormat(format) and then defaultTextFormat = format. When I set the TextField's htmlText property, the defaultTextFormat is suddenly reset to what it was originally.
    So something like:
    var view:MovieClip = new externalDefinition();
    var label:TextField = view.label;
    trace(label.defaultTextFormat.fontName)
    // Arial
    var format:TextFormat = label.getTextFormat();
    format.fontName = "Century Gothic";
    label.setTextFormat(format);
    label.defaultTextFormat = format;
    trace(label.defaultTextFormat.fontName)
    // Century Gothic
    trace(label.htmlText)
    // <TEXTFORMAT LEADING="-1"><P ALIGN="LEFT"><FONT FACE="Century Gothic" SIZE="18" COLOR="#271F60" LETTERSPACING="0" KERNING="1">label</FONT></P></TEXTFORMAT>
    label.htmlText = "<b>Hello!</b>"
    trace(label.defaultTextFormat.fontName)
    // Arial
    trace(label.htmlText);
    // <TEXTFORMAT LEADING="-1"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="18" COLOR="#271F60" LETTERSPACING="0" KERNING="0"><B>Hello!</B></FONT></P></TEXTFORMAT>
    So why does it do this? I understand why setting htmlText might reset the formatting to the default formatting but why does it change defaultTextFormat? Why doesn't it use the defaultTextFormat formatting I changed? Why does it use the original formatting the text field had when it was defined in asset library? How can I tell flash to use my formatting when I change htmlText? Where does it keep the original information stored and how does it revert back to it?
    Thanks,
    Erik

    It happens when you are using a TextField that is part of an exported library symbol from Flash Professional.
    If you want to reproduce the problem, you must create a new FLA file in Flash Professional. Make a library symbol. Add a TextField inside that library symbol. Give the text field an instance name like 'label', and some text. I am using _sans as the font face. Export the library symbol for actionscript in the symbol properties, give it a class name like "LabelExample". In the file's Publish Settings, set it to publish a .swc file. Publish it.
    Now include the .swc file in a new project. You should be able to make an instance of LabelExample. Make a new instance, like:
    var clip:MovieClip = new LabelExample();
    var textField:TextField = clip.label;
    Now apply a new defaultTextField to this text field. It will work as long as you only change the text property. Then try to change the htmlText property. Unlike a normal new instance of TextField, which will continue to apply your defaultTextFormat formatting to the text, even when htmlText is set, it will reset your defaultTextFormat to whatever it was originally when the symbol was published, and not use the defaultTextFormat you set. I don't have any idea why it would do this, it is inconsistent with how a TextField normally behaves and by all indication is supposed to behave. I believe this is a bug in the Flash framework. :/
    Thanks

  • My iPhone 4s 5.1.1 won't let me download or update any apps it's starts by saying "waiting" downloads half way then goes back to "waiting" and then does it again then says it can't download or update help

    My I phone 4s 5.1.1 won't let me download or update anything it starts by "waiting" then loads half way n goes bak to "waiting" then does it against then it says that it's unable to download or update help please I've tried signing out of my apple account and signin back in I've reset all settings I've turned it off and on idk what else to do!!

    I have decided to dedicate this thread to the wonderful errors of Lion OSX. Each time I find a huge problem with Lion I will make note of it here.
    Today I discovered a new treasure of doggie poop in Lion. No Save As......
    I repeat. No Save As. In text editor I couldn't save the file with a new extension. I finally accomplished this oh so majorly difficult task (because we all know how difficult it should be to save a file with a new extension) by pressing duplicate and then saving a copy of the file with a new extension. Yet then I had to delete the first copy and send it to trash. And of course then I have to secure empty trash because if I have to do this the rest of my mac's life I will be taking up a quarter of percentage of space with duplicate files. So this is the real reason they got rid of Save As: so that it would garble up some extra GB on the ole hard disk.
    So about 20 minutes of my time were wasted while doing my homework and studying for an exam because I had to look up "how to save a file with a new extension in  mac Lion" and then wasted time sitting here and ranting on this forum until someone over at Apple wakes up from their OSX-coma.
    are you freaking kidding me Apple? I mean REALLY?!!!! who the heck designed this?!!! I want to know. I want his or her name and I want to sit down with them and have a long chat. and then I'd probably splash cold water on their face to wake them up.
    I am starting to believe that Apple is Satan.

  • "Your session has timed out,try again." is the message I get every time I try to purchase a song on itunes. My last purchase was June 11, 2011, and nothing has changed since then.

    "Your session has timed out, try again." is the message I get every time I try to purchase a song. My last purchase was june of this year, and nothing has changed since then.

    I had this problem, but it was because I was clicking on an external link. Try instead going straight into iTunes, then going to the Podcast section. At the bottom of the "Podcast Quick Links" section, there's a text, "Submit a Podcast." Click on this instead. Once I did, I got to the same page as before, but it did process the feed.
    Good luck!

  • Need a shortcut to "Allow pages to choose their own colors, instead of my selections above option preference" I know where it is and how to use it but I have to go through 7 mouse clicks to change it, then a few minutes later change it back. I also k

    Need a shortcut to "Allow pages to choose their own colors, instead of my selections above option preference" I know where it is and how to use it but I have to go through 7 mouse clicks to change it, then a few minutes later change it back. I also know the sequnce is alt t, alt o, alt c, alt a, then ok, ok. Got to be a way to make a one key short cut for this. I use a black background to reduce eye strain, but about 10% of the webpage I go to can't be send with black so I have to go into tools and hit 6 or 7 things to chnage it then after through with webpage have to do it all over at Not allow webpages to have own color. Very very cumbersome.
    == This happened ==
    A few times a week
    == made that way

    https://addons.mozilla.org/en-US/firefox/addon/toggledocumentcolors-198916/
    The above addon will solve your problem.
    Shortcut to toggle user color/page color :- Ctr+Shift+C

  • TS1717 Error message appearsn 'This copy of iTunes is corrupted or is not installed correctly. Please reinstall iTunes'. It tells me new version installed and then does nothing?

    If I delete the current iTunes to reinstall latest version what happens to the music I have downloaded from my own cd collection, do I lose it as I haven't been able to back up my music?

    Let's try a repair install of iTunes first.
    Restart the PC. If you're using Vista or 7, now head into your Uninstall a program control panel, select "iTunes" and then click "Repair". If you're using XP, head into your Add or Remove Programs control panel, select "iTunes", click "Change" and then click "Repair".
    Can you launch your iTunes now?

  • Firefox won't install on my Mac, it just finishes the installation then does not appear in my Applications folder.

    Firefox offered to create a new profile for me, but took forever to do so so eventually I had to shut off the computer. In restarting, initially Firefox would not open as "Profile could not be found". Having moved Firefox to my trash folder, when I attempt to install Firefox again, it completes the download, then does not appear in my Applications folder.

    This is likely caused by a problem with the profiles.ini file and the profile marked as Default=1 in this file is not present on the hard drive.
    *Mac: ~/Library/Application Support/Firefox/
    You can use one of these to make Firefox create/use a new default profile:
    *Delete the profiles.ini file to force Firefox to create a new default profile
    *Use the Profile Manager to create a new profile
    *Use "Choose Folder" when you create a new profile to select the location of a lost profile and recover this profile
    *http://kb.mozillazine.org/Profile_Manager
    *https://support.mozilla.org/kb/Managing+profiles
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    Download and save the full Firefox installer to the desktop and start the installation with a double-click on the desktop icon.
    You can find the full version of the current Firefox 29.0.1 release in all languages and for all Operating Systems here:
    *http://www.mozilla.org/en-US/firefox/all.html
    See also:
    *http://kb.mozillazine.org/Installing_Firefox#Mac_OS_X

Maybe you are looking for