Auto-shift of focus between JTextFields

Greetings.
I have an array of 50 JTextFields which I restricted to a four-character entry limit. The limit works just fine, but I would like the focus to shift to the next JTextField when the limit is reached. Currently, I'm watching for the limit via an extended PlainDocument called CharLimitDocument. (*code included below) I know that Java offers the function FocusManager.focusNextComponent(Component aComp), but I'm not sure how to retrieve the current component. Can anyone help?
Thanks in advance,
Liz
*CharLimitDocument Code
import javax.swing.text.*;
import java.awt.*;
//This class overloads the Document so that a JTextField can be designed to accept only a specific number of characters.
class CharLimitDocument extends PlainDocument
private int limit;
public CharLimitDocument(int limit)
{  this.limit = limit;  }
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException
if((str.length() + getLength()) <= limit)
{     super.insertString(offs, str, a);     }
else
{     Toolkit.getDefaultToolkit().beep();     }
}//end class CharLimitDocument

Maybe you were talking about this function in javax.swing.JComponent?
hasFocus() (returns boolean)
You could test each component to see if it hasFocus() and then you'd be able to retrieve the 'current' component (pseudo code below). Even though you have fifty fields, this still woudn't be memory/processor intensive.
Hope that helps,
H
int compindex=0;
while((compindex)<=(getComponentCount()))
     if(getComponent(compindex).hasFocus()==true)
     {this is the current component... do whatever;}
     else
     {compindex++;}
}

Similar Messages

  • Change the focus between two windows

    I have a program that uses a console window, and an appletviewer window. I want to know the code required to change the focus between each of the windows. By focus I mean which window is on top of the screen.

    These are java.awt.Frame or javax.swing.JFrame objects, right? Use their show() method. Some OS's may not allow you to steal focus. You could try:
    frame1.hide();
    frame2.hide();
    if(wantframe1ontop)
    frame2.show();
    frame1.show();
    else
    frame1.show();
    frame2.show();
    }

  • Move focus between elements of browser page doesn't work with JVM 1.6.x

    Hi,
    why JVM 1.6 doesn't support accessibility?
    with JVM 1.5_10 or above it's possible to move from elements of IE browser page with tab and enter and exit from applet
    with JVM 1.6 or using plugin 1.6 this is not more possible.
    with plugin 1.6 and JVM 1.5 applet can gains focus but it doesn't release it
    with JVM 1.6 applet doesn't gain focus and all keyevents are intercepted from browser.
    to make my applet and page accessible I need to move focus between elements of browser page with tab,
    and enter and exit from applet.
    Just because my users can't use mouse but only keyboard.
    Note that FireFox doesn't work at all, even if bug seems fixed https://bugzilla.mozilla.org/show_bug.cgi?id=93149
    (you can watch a recorder right sample here on: http://www.vista.it/ing_vista_0311_video_streaming_accessibile_demo.php)
    Please advise.

    Hello Carl,
    some things are so easy if some one takes place the clou. I clear all cache information in the firefox browser and all is working fine.
    Thank you very much and have a nice weekend.
    Regards
    Thorsten

  • Anyway to "UN" Ken Burns stills globally or as default bringing in jpeg's?  New to iMovie. I have 3 titles that build.  First is logo, add prod't name second line, add date 3rd line.  They shift when dissolving between them. Title function NG for this.

    Anyway to "UN" Ken Burns stills globally or as default bringing in jpeg's?  New to iMovie. I have 3 titles that build.  First is logo, add prod't name second line, add date 3rd line.  They shift when dissolving between them. Title function NG for this.
    The people at the Apple store gave me a long, tedious workaround which is open Pages and bring in logo.  Export it as a PDF.  Open the PDF in Review and then "Save As" a jpg to the desktop and drag and drop into the imovie.  Even with this process, the text will sometimes shift.  When it works, it looks good, the logo comes up, then the second line fades in under it as part of the build and then the third line completes the graphic.  It would something this easy and straight forward would be easy. 
    HarveyV

    I did the work around for the titles/jpg's in this short video. 
    I'll try your fix on the next one.  I have 22 short 3-5 minute videos to produce
    and I'm on number 5.  This should save me a bunch of time. 
    It would appear that you know more than the guy at the Apple Store. 
    Thank goodness for on-line forums.
    I already tried fixing them individually as you suggested,
      by going the crop/fit route.  However, even then,
      the second in the series had always shifted. 
    The first and the third images lined up, but not number 2.. 
    So  I brought in all the images, (1, 2 and 3).  
    and then the 2nd image again and put it in the third position
    in the sequence on the time line. I deleted the "original" 2nd image.
    So I had 1, 3, then 2.  Then I dragged and dropped the correct number two
    into position two and it worked.  So what happens is that the
    client logo appears, then that stays put and the next line dissolves in
      and then the third dissolves in.  They are three separate titles, but they
    are aligned perfectly so that they build as I dissolve between them.
    I think the problem with the edit copy route would be that while
    I could edit/copy the logo, I couldn't position text through the
    iMovie text function exactly as it only gives you middle or bottom third etc.
      Each title with the product name is positioned individually depending on
    length and number of lines. By going through Pages, I can position the logo
    and the text exactly.  Also, some logos are horizontal, while others
    are square etc., so text positioning is crucial.Anyhow,
    I'll try the global approach for the next one and see how that works.
      Thanks very much for your insight and especially for your prompt reply.
    I trust you're inside on this gorgeous July 4th because you're
    making money on your computer. ;-)HarveyVOn 7/4/2011 3:57 PM, Apple Support Communities Updates wrote:
    > Apple Support Communities <https://discussions.apple.com/index.jspa>>>>       Re: Anyway to "UN" Ken Burns stills globally or as default>       bringing in jpeg's? New to iMovie. I have 3 titles that build.>       First is logo, add prod't name second line, add date 3rd line.>       They shift when dissolving between them. Title function NG for...>> created by AppleMan1958 > <https://discussions.apple.com/people/AppleMan1958> in /iMovie/ - View > the full discussion > <https://discussions.apple.com/message/15552380#15552380>> ------------------------------------------------------------------------>> I am baffled by what you are asking...but if you are asking how to > turn off the Ken Burns effect, you can do it for future photos you add > by going to File/Project Preferences and setting the default initial > photo placement to FIT or CROP rather than Ken Burns.>> For a global change on photos that are already in your project, pick a > photo. Open the Rotate, Crop, Ken Burns Tool. Select FIT or CROP.  > Exit the tool. Now select this same photo and EDIT/COPY.>> Now, EDIT/SELECT ALL.>> Finally, EDIT/PASTE ADJUSTMENTS.../CROP ADJUSTMENTS.

  • Since installing the latest update of Photoshop CC two days ago, Auto Blend for focus stacking is selecting all pixels from the bottom layer instead of selecting the ones in best focus from each layer. Has anyone else seen this problem?

    I installed the latest update of Photoshop CC two days ago on my Macbook Pro, and now when I try to do focus stacking by opening multiple photos and doing Auto Align and Auto Blend, the blend selects the entire bottom layer instead of selecting the in-focus areas from each layer. I even tried again on a series of images where this worked a week ago and the problem occurs. I have Photoshop on a Windows 8 machine and did not apply this latest update and it works fine. Has anyone else encountered this?

    And since installing this same update, my Photoshop is crashing just after starting.
    Ashutosh.Nigam suggested me in this forum to change the permissions to SLStore & SLCache Folder, but it did not work.
    Ali from french Adobe support told me to delete my Settings files, but it was not enough.
    A girl with no name from the same team told me to update my video card driver, but you know I run the latest Mac OS X version and everything is updated, mademoiselle.
    Stephane sent me a link to a huge page of things to do :
    -  Troubleshoot account-specific fonts, but there wasn't any corrupted font
    - Delete account-specific Adobe cache files but... guess what...
    - Troubleshoot account-specific login items but... yes, that's it, I can see you understand me
    - Reset the access settings on the user account's Library folder... oh god, that was fun, I used the Terminal and sudo commands
    I did all of these things because when I tried to open PhCC in an other admin session, it worked, so that was an incompatibility between my session and PhCC. But, but, but, when I tried again to lauch the app in the second session, it worked fine but refused to quit. Ha ha ha.
    So you can try to delete your Settings files. I wish it'll work for you. If not you can try the long list above... or hope a better answer from the support.
    I didn't change anything but Photoshop on my session and they ensure that the bug is due to my session and not to their update. Strange affair.
    Good luck,
    JLuc

  • Problem with gaining focus for JTextField in JTabPane

    I have 2 tabs. The first one has a "save to file" puush button, the seccond has two textfields. When I push the save button I get a warning that not all fields in the seccond tab are filled. If I choose the first button it shows me the seccond tab and searches for the first empty field. Then it should set the focus to that field but it doesn't. Here's the code:
    void goToEmptyField() {
            tabs.setSelectedIndex(1);
            JTextField field =  (nameField.getText().length() == 0) ? nameField : actionField;
            field.requestFocusInWindow();
        }The code for determining the first empty field works fine. I'm not sure if the seccond tab gets focus or just shows up. It doesn't have the light rectangle at the tab's description. Could anybody help me please?

    seems to work OK in this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      JTabbedPane tabs;
      JTextField nameField = new JTextField(20);
      JTextField actionField = new JTextField(20);
      public Testing()
        setLocation(400,300);
        setSize(300,200);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel jp1 = new JPanel();
        JButton saveBtn = new JButton("Save");
        saveBtn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            if(checkFields()) saveData();}});
        jp1.add(saveBtn);
        JPanel jp2 = new JPanel();
        jp2.add(new JLabel("Name: "));
        jp2.add(nameField);
        jp2.add(new JLabel("Action: "));
        jp2.add(actionField);
        tabs = new JTabbedPane();
        tabs.addTab("Tab 1",jp1);
        tabs.addTab("Tab 2",jp2);
        getContentPane().add(tabs);
      public boolean checkFields()
        if(nameField.getText().equals("") || actionField.getText().equals(""))
          JOptionPane.showMessageDialog(this,"field/s empty");
          goToEmptyField();
          return false;
        return true;
      public void goToEmptyField()
        tabs.setSelectedIndex(1);
        JTextField field =  (nameField.getText().length() == 0) ? nameField : actionField;
        field.requestFocusInWindow();
      public void saveData()
        JOptionPane.showMessageDialog(this,"Saving data...");
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • How to auto-populate form fields between documents?

    I'd like to create an interactive form where the user inputs data into different fields and then the data gets auto-populated into other fields in forms linked to the original form. Is this possible with Acrobat XI? If not, then which Adobe product is best suited for this? If it's possible, how difficult is this to do? I don't need exact "how to" tips at this point. I am not a developer and I don't have any experience with Action Script. I'm just researching what products I can use, as a non-techie, to do the job. Thanks.

    Thanks for your reply. I'm having a hard time understanding the functionality on the end-users's side with the different Adobe forms products. I did a little more reading up on this, but it's still not 100% clear. Perhaps you can help clarify.
    Scenario 1: The user does NOT have a copy of Acrobat XI on their end, and  I do NOT have a subscriptiont to FormsCentral, and I do NOT enable import/export features in the form using Adobe LiveCycle Reader Extensions. In this scenario, the user can fill out my form, but they can't save a copy of the completed form on their local drive. I, however, get a copy of the completed form where I can then extract and analyze the data.
    Scenario 2: The user does NOT have a copy of Acrobat XI on their end, but I have have a subscriptiont to FormsCentral. The user can complete the form and save it on their local drive, but I can't have data auto-populate from one to another. (Note: I went to the FormsCentral website and it says "Allow respondents to download the PDF form, print out, save, EDIT and submit later." I interperet that as meaning they can add text to a fillable form and save it on their end.)
    Scenario 3: The user does NOT have a copy of Acrobat XI on their end, but I have enabled the form with LiveCycle Reader Extensions so that I can have data auto-populate from one form to another. However, I have to pay for an Extension license fee. I managed to find the pricing, and it's too expensive for my needs right now. I'm looking to share the forms with students, so this is not an option.
    Scenario 4: The use HAS Acrobat XI. I can get data to auto-populate from one form to another and the user can complete and save on their local drive. This scenarios is not an option for me / Can't get students or schools to pay for a full license of Acrobat XI is not an option at this point.
    Is my understanding correct? If so, I feel like I've hit a dead-end. The only cost-effective solution is to have a simple fillable form without the ability to auto-populate data between forms. Sigh.
    Thanks.

  • Focus on JTextfield in JDialog box

    A JDialog box is being opened from a menu.
    There is only one JTextfield on the dialog box and 2 buttons.
    The focus is not on any of the components in the dialog box and I want it on the textfield by default.
    I have tried all the requestFocus(),requestDefaultFocus(),grabfocus() etc and none of them work.
    There is an eventListener added to the JTextfield could this be the problem.

    I am a little supprised that the focus is not given to the text field if that is the only thing on the dialog.
    You could try detecting the display of the dialog and then giving the focus to the text field. Focus will not be given to a component if the component cant be displayed at that time. My guess is that the dialog is still hidden when you are trying to set the focus and that is what is causing the problem.

  • How to set focus on JTextField

    hi everyone,
    i have a JTextFields on my form. i have a reset button. i want keh when i click it all the fields get default value(that i have done) and focus is set on any of the JTextFields. please tell me how to do that.
    thanks & regards

    i triend using requestFocus method but i coouldn't get
    please tell me the wayread the docs
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComponent.htmlor, post a small demo program explaining:
    what it is you expect, and
    what it is you get

  • Requesting focus for JTextField inside JPanel

    I have an application with following containment hierarchy.
    JFrame --> JSplitPane --> JPanel.
    JPanel is itself a seperate class in a seperate file. I want to give focus to one of the JTextfields in JPanel, when the JPanel is intially loaded in the JFrame. I believe that I cannot request focus until the JPanel is constructed. I can set the focus from JFrame (which loads JPanel) but I want to do this from JPanel. Is there any technique to request focus from the JPanel itself (preferably during JPanel construction).
    regards,
    Nirvan.

    I believe that I cannot request focus until the JPanel is constructedYou can't request focus until the frame containing the panel is visible. You can use a WindowListener and handle the windowOpened event.

  • Can't get focused a JTextField within a JTable cell

    I have a table and I placed a cell editor with a JText field on it for all cell editing,
    I want to do things when the focus is lost or gained and my app works fine when a cell is double clicked or f2 is pressed, but when a cell is selected (without double clicking) and just begin typing it produces no focus gained event.
    I tried by calling grabFocus method of that jTextField within the overriden prepareEditor method of the JTable but it doesn't get focus (doesn't even gains and loses it :s )
    Does anyone have an idea of how to force this component to grab focus?
    Thanks

    Hai,
    dont add the FocusListener to the EditorComponent.
    Try to use the JTable Functions - like this:
    import javax.swing.event.ChangeEvent;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.EventObject;
    import javax.swing.*;
    public class Test extends JFrame
         JTable table;
         JTextArea text;
         JScrollPane scroll;
         JTextField cellTextField;
         Test()
              DefaultTableModel model = new DefaultTableModel();
              cellTextField = new JTextField();
              text = new JTextArea();
              text.setEditable(false);
              scroll = new JScrollPane();
              scroll.setViewportView(text);
              table = new JTable(model){
                   @Override
                   public Component prepareEditor(TableCellEditor editor, int row, int column) {
                        text.append("Better use this to Start Edit!\n");
                        return super.prepareEditor(editor, row, column);
                   @Override
                   public void editingStopped(ChangeEvent e) {
                        text.append("Better use this to Stop Edit!\n");
                        super.editingStopped(e);
              model.addColumn("Column 1");
              model.addColumn("Column 2");          
              model.addRow(new String [] {"Cell 1", "Cell 2"});
              table.setCellSelectionEnabled( true );
              table.getColumnModel().getColumn(0).setCellEditor( new DefaultCellEditor(cellTextField));
              table.getColumnModel().getColumn(1).setCellEditor( new DefaultCellEditor(cellTextField));
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(table, BorderLayout.NORTH);
              getContentPane().add(scroll, BorderLayout.CENTER);
              setSize(300, 300);
              setVisible(true);
              setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
         public static void main(String[] args)
              new Test();
    }

  • Getting focus on JTextField?

    I made a chat with a JApplet. In my chat i have a JTextField where users can write messages. I want to have focus on this JTextfield all the time, the user should not be allowed to get focus somewhere else. How can I do that? I tried requestFocus(); but its not making any differants. I use gridbaglayout and this is how I create my JTextfield:
    beskedFelt = new JTextField(10);
    c.insets = new Insets(10,0,0,0);
    c.gridx = 1;
    c.gridy = 2;
    gridbag.setConstraints(beskedFelt, c);
    contentPane.add(beskedFelt);
    beskedFelt.setEditable(true);
    beskedFelt.addActionListener(this);
    beskedFelt.requestFocus();
    thx for your time....

    yesss it worked:
    beskedFelt = new JTextField(10);
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    beskedFelt.requestFocus();
    c.insets = new Insets(10,0,0,0);
    c.gridx = 1;
    c.gridy = 2;
    gridbag.setConstraints(beskedFelt, c);
    contentPane.add(beskedFelt);
    beskedFelt.setEditable(true);
    beskedFelt.addFocusListener(this);
    beskedFelt.addActionListener(this);
    public void focusGained(java.awt.event.FocusEvent fe)
    public void focusLost(java.awt.event.FocusEvent fe)
              Object source = fe.getSource();
              if ( source == beskedFelt)
    beskedFelt.requestFocus();
    thx a lot ppl....

  • Auto-Stack by interval BETWEEN photos

    Hi,
    I want the auto-stack feature to pick up the shots that I take in a burst, regardless of the shutter speed that they are taken at. At the moment the auto-stack seems to check the time-difference between the capture time of the photos; this is useful to a degree, but I would prefer a method where the time-difference in calculated between the end of one photo and the beginning of the next -
    e.g. "[Capture time of photo 2] - ([capture time of photo 1] + shutter speed)" < specified auto-stack time
    This would allow me to stack all shots that are taken in a burst, regardless of the actual shutter speed. This woulkd mean that low-light HDR bursts with AEB which result in shutter speeds of up to 30s would stack correctly, and be seperate to the next HDR burst even if it started 1 second later!
    Gary

    However I find the capture time of photos in any one stack exceed 1 minute!!  For instance, these are the capture times of photos in a single stack:
         8:19:12PM, 8:19:25PM, 8:19:43PM, 8:20:24PM, 8:21:19PM, 8:21:45PM
    This is a maximum interval setting.  It has nothing to do with the total timespan of the whole sequence. Just, how closely-spaced the individual shots  were. These were less than half a minute apart.
    IOW: how long can pass between one shot and the following one, before that is no longer considered to be part of the same continuing sequence.
    RP

  • How to Handled Shift +Tab(Focus) click in radion button?

    Hi,
    I am using Jdeveloper 11.1.2.0.
    My scenario is one radio button having three items(Left,Right,Center). Now my radio button focus is first radio(Left). Now I click the the tab sequence. It will go to the next field, whether it is input field.
    Suppose Now I am come to back ward like shift+Tab it is come to the radio button. Here what is happening mean the focus is going to the Last radio button item(Center), what I want is which radio Item I select Initially ,the Same Place cursor want to go. How to proceed to this. Please give some suggestion to proceed.
    Regards,
    Ragu

    Hi,
    so what you are saying is that the tab focus navigation bypasses the other radio buttons whereas tab back focus navigation doesn't. If this is the case, and due to missing information in your question, try this
    set autosubmit="true" on the radio group so the radio button selection is saved.
    If this doesn't help, please provide information about the implementation of how you created the radio group and which data they are bound to. Chances are that this indeed needs to be filed as a bug but also that it is a problem in your model
    Frank

  • Color shift (gamma?) between XDCAM Ex and PROres

    Hi,
    We have edited a show in Apple XDCAM EX in 23,98 HD. We did a QT movie of that sequence into the native codec that we edit with (Apple XDCAM EX).
    Into quicktime, or even in compressor, we re-export ta video into Apple Pro Res and we are experiencing a big color shift between both codec.
    Somedoby have an idea on that?
    Thank you!
    Nicolas

    There's a know shift in the gamut between the two recording methods because of the compression scheme.
    If you search the posts here and on the Cow, you'll find other references to it.
    You might want to consider working in ProRes all the way through. It's a good way to even out all the differences between source footage and act as a neutral Digital Intermediary. The nice thing is that it's tuned to run on the machines and runs very efficiently. It's been a big help here when I've had mixed footage, or have to go out to all the different formats and uses that I do. I get no shifting at all, even between proxy and HQ. So I can do all my editing and effects in lightweight proxy and then conform to the more space demanding 422 or HQ.

Maybe you are looking for

  • I made new apple id but I don't activate by email so than set in my iCloud

    I made new apple id but I don't activate by email so than set in my iCloud id on iphone but I want find phone or use iCloud it does nt accept i try so many hours but I am so tired. my iphone is lock now . i waiting for your answer . thank you

  • Html file blank on secondary computer

    I'm stumped on this. I just sent a website I had built in dreamweaver using a fluid grid layout to a client just to show him the work in progress. It is working fine from my computer however he is seeing a blank index file in his browser. I'm 100% su

  • Upgrade now missing old photo library

    My Mom just upgraded her iLife suite and when she did I think sh emiss selected the upgrade any old librarys and now has no access to the old photos. Is there an easy way to transfer these photos to the new iPhoto program library? Thanks! Doug

  • Is it possible to upload a xls file into an application and store in table.

    Hello, I just want to know whether its possible to upload a xls file into application in Oracle 10g . i.e. have a separate xls file stored in computer then in the application just have a browse button to upload that xls file and that data should be i

  • Exception Aggregation or Avg Inventory

    Hi, While I am doing Inventory Development, got some issues in reporting. Below is my reporting info. Chars in rowsr:  CompCode, Sector(Nav attribute to plan), Calmonth. 1. We get Closing Inventory in runtime ( 0valstockval ) 2. Turnover (Just a KF)