Set focus on TextField

Hi guys,
I want to focus the textfield with a cursor on it without
clicking on the same and without using Ifocusmanager as I have
taken the textField.
I have tried
stage.focus but it doesn't seem to work the way I want.
please help me..

It works.. But without clicking stage won't it happen?
I have one more query related to it..
I have n number of tfs on the stage and when I enter into the
the first tf and if it reaches the maxchar no. it
shifts its focus to the next tf. Now If I want to reenter the
text into these tfs from the start it won't replace the text
(for this i wrote tf .text="", cause of this it takes only
single char irrespective of the maxchar limit! ) So is there any
method to do it? Cause in focusmanager class it happens..and
I want to make it work without one..

Similar Messages

  • How can I set focus on TextField?

    Hi,
    I can't find a method or solution to set focus on TextField,I'd like to set the cursor into a special TextField when user enter my form.how can i implement this functionality?
    Any suggestion?
    Hanlin Li.
    Edited by: noob on Apr 13, 2012 4:28 PM

    textField.requestFocus();

  • Setting focus to textfield when program is first launched

    I'm getting really mad. Everything is working fine. But, one little thing and its is suppose to be really simple. I must be some kind of an idiot if I can't see what the problem is for this. Anyway, I'm trying to set the cursor/focus on my text field when the program is launch. But, it seems that everyting that I try appears not to be working. I now have some junk code in my program. But, I was hoping that my attempts were getting me close to what I want. Below is my code. I'm hoping someone can tell what I'm doing wrong.
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    class ChatClient extends Frame
        private TextField tf1 = new TextField("", 50);
        private TextArea ta;
        private Button sendButton;
        private Button quitButton;
        private MenuItem exitMT, aboutMT;
        private Choice choice;
        private String user;
        public ChatClient()
          super("ChatClient");
         addWindowListener(new WindowAdapter()
          {public void windowClosing(WindowEvent e) {System.exit(0); }});
          setTitle("Chat Room");
          Panel p = new Panel(new BorderLayout());
          Panel p1 = new Panel(new BorderLayout());
          Panel p2 = new Panel(new GridLayout(3,1));
          MenuBar mb = new MenuBar ();
          setMenuBar (mb);
          Menu fileMenu = new Menu ("File");
          mb.add(fileMenu);
          Menu helpMenu = new Menu ("Help");
          mb.add(helpMenu);
          fileMenu.add (exitMT= new MenuItem ("Quit"));
         helpMenu.add (aboutMT = new MenuItem ("About"));
          exitMT.addActionListener(new ExitCommand());
          aboutMT.addActionListener(new AboutCommand());
      //creating main panel
         add(p, BorderLayout.NORTH);
          ta = new TextArea(10, 50);
          add(ta, BorderLayout.CENTER);
          ta.setSize(500,300);
          ta.setEditable(false);
          ta.transferFocus();
        //adding buttons  and choice box to the right side of the window
          sendButton = new Button("Send");
          Panel p3 = new Panel();
          sendButton.setSize(15,15);
          sendButton.setBackground(Color.green);
          p3.add(sendButton);
          p2.add(p3);
         sendButton.addActionListener(new CopyCommand());
         quitButton = new Button("Quit");
          Panel p4 = new Panel();
         quitButton.setSize(15,15);
         quitButton.setBackground(Color.red);
         p4.add(quitButton);
         p2.add(p4);
         quitButton.addActionListener(new ExitCommand());
         Panel p5 = new Panel();
         choice = new Choice();
         choice.addItem("John");
         choice.addItem("Jena");
         choice.addItem("Colleen");
         choice.addItem("Steve");
         user=choice.getItem(0);
         p5.add(choice);
        choice.addItemListener(new CopyCommand());
        p2.add(p5);
        add(p2, BorderLayout.EAST);
       //adding the textfield to the south end of the window
          p1.add(tf1);
          tf1.isDisplayable();
          tf1.setFocusable(true);
          tf1.setVisible(true);
          tf1.requestFocus();
          add(p1, BorderLayout.SOUTH);
          tf1.addActionListener(new CopyCommand());
    //handling ActionEvent from buttons and menu items
      class ExitCommand implements ActionListener
        public void actionPerformed (ActionEvent e)
               tf1.setText("");
               ta.setText("");
              choice.select(0);
              System.exit(0);
      class AboutCommand implements ActionListener
         public void actionPerformed (ActionEvent e)
               System.out.print("About menu was pressed!");
      class CopyCommand implements ActionListener, ItemListener
        public void itemStateChanged(ItemEvent e)
         {  if (e.getSource() instanceof Choice)
                   user = (String)e.getItem();
        public void actionPerformed (ActionEvent e)
                ta.append(user + ": " + tf1.getText() + "\n");
                tf1.setText("");
                tf1.requestFocus();
         public void keyPressed (KeyEvent ke)
                //figure out if the enter key was pressed
                 if (ke.getKeyCode() == KeyEvent.VK_ENTER)
         ta.append(user + ": " + tf1.getText() + "\n");
              tf1.setText("");
                tf1.requestFocus();
         public void keyTyped (KeyEvent ke) { }
         public void keyReleased (KeyEvent ke) { }
       public static void main(String[] args)
       {  Frame f = new ChatClient();
          f.setSize(600, 400);
          f.show();
    }

    Bingo!
    Hi , I am trying to make a chat application too I dont know its exactly like yours or not......I need to make it for the chat support of a website (like in some sites you have online chat with chat center guy's). For that reason I had to make it an applet , although i want to use frame but i do then how i will embed it in the web page? I encountered with the same problem you are facing but didnt solved it yet cause i have bigger problems than that. tell me you have solution.
    Plz visit the following threads:
    http://forum.java.sun.com/thread.jspa?threadID=611865
    and
    http://forum.java.sun.com/thread.jspa?threadID=607639
    Thankyou
    Regards
    Manu

  • Back again - set focus

    Hi again,
    I've been struggling with setting focus on each instance of a field within a repeating subform. My subform is limited to 5 instances. Min of 1.
    As the user exits the only textfield in the subform, I have a new instance creating. I want the focus set to the new instance but I have not been able to get anything to work. My latest attempt has been to try to pass a count using the instancemanager to a variable in the setfocus string.
    Here is what I have thus far. I know I need to resolve the node but that process is confusing the heck out of me. I've read and re-read everything I've been able to find but I havent been able to wrap my head around that part successfully.
    Can anyone point me in the correct direction or suggest a better solutions? TIA!
    form1.Account_Client_Information.Long_Title.Account_Long_Title::exit - (JavaScript, client)
    var oSubform = xfa.resolveNode("Long_Title");
    var oNewInstance = oSubform.instanceManager.addInstance(1);
    xfa.form.recalculate(1);
    var count = (this.instanceManager.count)
    xfa.host.messageBox("Text Field Index in new Subform: " + count);
    var vfocindex = xfa.resolveNode("Account_Long_Title[count]");
    xfa.host.setFocus(vfocindex);

    Hi,
    The addInstance method will return the subform that you want so you only need to do;
    var oNewInstance = Subform1.instanceManager.addInstance(1);
    xfa.host.setFocus(oNewInstance.Account_Long_Title)
    Regards
    Bruce

  • Setting focus to new instance of a field...need help.

    Hi there,
    I have a flowed form which consists of multiple subforms. I have one subform which is basically one textfield that is set to a min of 1 and a max of 5.
    These are to correspond to fields in our system of record that have 5 fields for company long name with a 36 character field limit.
    I've got the limits set up just fine and I have added simple script to add a new instance when the user exits the field.
    The focus goes to the next field set in the tab order but what I want is the focus set on the new instance of field created but I have not been able to find an example of how to do that.
    Any suggestions would be greatly appreciated. Thanks!

    Well,
    I've been reading and trying various things but cant get anything to work like I want it to.
    The sample provided works for 2 iterations but mine has to do this for up to 5 instances. I have not been able to figure out how to get this to work.
    Anyone have any additional suggestions?
    btw...here is my modified version. ES2 is whay I'm using.
    Long_Title.occur.max = "5";
    var oSubform = xfa.resolveNode("Long_Title");
    var oNewInstance = oSubform.instanceManager.addInstance(1); // I think you probably managed this first part better than here
    xfa.form.recalculate(1); // I THINK THIS IS IMPORTANT
    var count = (this.Long_Title.nodes.length)
    var testIndex = oNewInstance.Account_Long_Title.index;
    xfa.host.messageBox("Text Field Index in new Subform: " + count); // TextField1 will conserve index 0 because it is the only textfield in the new Sub1
    var NEW_TEXTFIELD = xfa.resolveNode("Long_Title[1].Account_Long_Title[0]"); // However, Sub1 gets index 1 because it is not alone any more
    xfa.host.setFocus(NEW_TEXTFIELD); // This actually sets focus on the newly created instance of TextField1 (actually Sub1 instance)

  • How to set focus order of multiple Component in a Frame

    I have created a Frame with contain some Label, Textfield, Choice and Buttons
    How do set focus order on these Components

    write an implementation of
    import java.awt.*;
    public class PanelFocusTraversalPolicy extends FocusTraversalPolicy
        public Component getComponentAfter(Container container, Component component)
            if(component.equals(cmp1))
                return cmp2;
            if(component.equals(cmp2))
                return cmp3;
            return cmp1;
        public Component getComponentBefore(Container container, Component component)
            //implentation of method
        public Component getDefaultComponent(Container container)
          return cmp1;
        public Component getLastComponent(Container container)
            return cmp3;
        public Component getFirstComponent(Container container)
           return cmp1;
        public PanelFocusTraversalPolicy()
    }and set the focus traversal of frame.
    setFocusTraversalPolicy(new PanelFocusTraversalPolicy())

  • Problem using Setting Focus

    Hello there, can you help me on how to use the set Focus.
    For instance I have a 3 JTextField, when I run it, the focus is on the first textField, what I want is that, when I pressed the enter key on the keyBoard, the focus will be on the 2nd textField, and when I pressed again the enter key, the focus will be on the 3rd textField and so on.
    can you give me a sample code on this one, thanks.

    the last post in this thread might give you some ideas
    http://forum.java.sun.com/thread.jspa?threadID=713697&tstart=0
    note: will only work if the textfields follow each other in the focus traversal policy

  • How to retain focus in Textfield

    I have one panel which contains three textfiled and one ToolBar. on clicking tool bar button certain dialog get opened.
    intially foucus remained on first textfield but when i do open the dialog with tool bar button. focus doesn't get return to first textfield even focus doesn't get back to screen.
    And my requirement is that to get focus on first textfield after closing the dialog.
    Please let me know if you have any suggestions.
    Thanks,

    yeah I need to set focus again on textfield and that is my question.you can do that using something like :jTextField.requestFocus(); I am seeking the event on which i can set the focus again please suggest.If you are using JOptionPane just add the above statement after showing dialog like JOptionPane.showInputDialog("Hello");
    jTextField.requestFocus();If you are using your own dialog, have a refrence to the textfield in the dialog and at 'windowClosing' Event use the mentioned statement.
    I think that should work....
    Thanks!

  • Cant get Focus on textfield

    Hi
    I have a class extending JFrame say "MainFrame" which consist of JSplitPane say "splitPaneA"
    splitPaneA has top and bottom component.
    TopComponent is another JsplitPane say "splitPaneA-B"
    splitPaneA-B consist of a Jpanel say "B-rightPanel "as RightComponent and another JPanel as left.
    splitPaneA has bottomcoponent which is Jpanel class say "BottomPanel " extendingJPanel
    splitPaneA .setABottomComponent(new BottomPAnel());
    BottomPanel has JtoolBar say toolBar
    ToolBar has a JtextFiled say textField1 which needs to be focused as soon as bottomPanel loads.
    I tried using following in BottomPanel class
    this.setEnabled(true);
    this.setFocusable(true);
    this.setVisible(true);
    this.requestFocusInWindow();
    textField1.requestFocusInWindow()
    But textFiled never gets focused.I also tried requestFocus method.
    In class MainFrame
    FocusManager.getCurrentManager().getFocusOwner()); always returns null
    (FocusManager.getCurrentManager().getFocusedWindow()); returns null
    this.hasFocus()); returns false
    Any help is greatly appreciated.

    Thanks for your responses.
    This is my compilable,executable dummy code.I have taken out lines which are not relevant to focus issue as well as the import.Please llet me know what can be done to get the focus in textfield as soon as window loads.
    public class DummyObjectSearchPanel extends JPanel implements ActionListener
    JTextField textField1;
    JButton searchButton;
    ImageIcon searchIconIcon;
    JToolBar jToolBar1;
    private static Icon closeIcon = new ImageIcon(ObjectSearchMainPanel.class.getResource("/resources/images/close_small.gif"));
    private JButton closeButton;
    JFrame frame;
    private String newline = "\n";
    public DummyObjectSearchPanel()
    this.setLayout(new BorderLayout());
    this.setBorder(new ShadowBorder());
    textField1 = new JTextField();
    this.setEnabled(true);
    this.setFocusable(true);
    this.requestFocusInWindow();
    this.setVisible(true);
    textField1.requestFocus();
    System.out.println("has focus " + textField1.hasFocus());
    jToolBar1 = new JToolBar();
    frame = new JFrame();
    frame.setUndecorated(true);
    jbInit();
    void jbInit()
    searchButton = new JButton();
    searchButton.setText("SearchButton");
    closeButton = new JButton(closeIcon);
    ActionListener al = new ActionListener()
    public void actionPerformed(ActionEvent ae)
    textField1.requestFocusInWindow();
    textField1.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(ActionEvent e)
    searchButton_actionPerformed(e);
    jToolBar1.setBorder(null);
    jToolBar1.addSeparator();
    jToolBar1.add(closeButton);
    closeButton.setOpaque(false);
    closeButton.setMargin(new Insets(4, 4, 4, 4));
    Dimension closeBtnDimension = new Dimension(20, 20);
    closeButton.setPreferredSize(closeBtnDimension);
    closeButton.setMinimumSize(closeBtnDimension);
    closeButton.setSize(closeBtnDimension);
    closeButton.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(java.awt.event.ActionEvent evt)
    //closeButton action taken out to make code short
    jToolBar1.addSeparator();
    jToolBar1.addSeparator();
    jToolBar1.add(textField1);
    jToolBar1.addSeparator();
    jToolBar1.add(searchButton);
    jToolBar1.addSeparator();
    jToolBar1.addSeparator();
    this.add(jToolBar1);
    searchButton.addActionListener(new java.awt.event.ActionListener()
    public void actionPerformed(ActionEvent e)
    searchButton_actionPerformed(e);
    textField1.requestFocusInWindow();
    void searchButton_actionPerformed(ActionEvent e)
    //searchbutton logic removed to simplify the code
    private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("New Search");
    Dimension d=new Dimension(600,100);
    frame.setSize(d);
    frame.setMinimumSize(d);
    frame.setPreferredSize(d);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    //Create and set up the content pane.
    JComponent newContentPane = new DummyObjectSearchPanel();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.getContentPane().add(new DummyObjectSearchPanel(),
    BorderLayout.CENTER);
    //Display the window.
    //frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    public void actionPerformed(ActionEvent e)
    // TODO Auto-generated method stub
    Thanks you so much

  • Setting focus on a component from backing bean

    Is there an easy way to set focus in a specific component on the jspx from a method in the backing bean? (other than javaScript coding...)

    Hi,
    did you take a look at
    About control the cursor position in a JSF web page
    It contains some links to other weblogs. The links are helpfull. Maybe you'll be able to find your solution there......
    Good luck
    Luc Bors

  • How to set focus on a input field in a selected row of a table?

    In a previous discussion (http://scn.sap.com/thread/3564789) I asked how to access an input (sap.m.Input) field of a selected row in a table. In the answer that was supplied I was shown how to get the items of the table. Then using the selected index to get the selected item get the cells. Then I could set editable on the proper cell(s). This worked fine.
    Now I need to set the focus on one of the fields. I tried something like this:
                var oNewLink = table.getSelectedItem();
                var oNewLinkName = oNewLink.getCells()[1];
                oNewLinkName.focus();
    But this doesn't seem to work.
    I have searched through other discussions and have seen this technique for putting focus on a field if you have its ID:
    sap.ui.getCore().byId(id_of_the_input_field).$().focus();
    In my case though I do not have an ID since the row and its cells are generated. How can I set focus on the cell of a certain row in a table?

    Hello Venkatesh. Yes that code does work. First I tried it on a table cell that was already rendered and it did work. The next time I tried it on a table row that was being added and it did not work there. So I added an on after rendering function for the table and added that code there. That did not work until I added a delay (timeout) to do a context switch before calling the focus and that worked.
    Once last thing though sometimes when I call focus on an input field (actually in a table row cell) if the field has text in it already the flashing cursor is at the beginning of the text and other times it is at the end of the text (which is the desired way). It depends on where I click in the row. Is there anyway to make sure the flashing cursor is at the end of the text when the focus is applied to a field that contains text?

  • How to set focus on the title of JTabbedPane

    I have created a JTabbedPane and added three JPanels to it. They are titled, say "Panel 1", "Panel 2" and "Panel 3". And each of them contains buttons and text areas. Since this app is for physically disabled users, it must provide navigation through these three tabs with keyboard operations only (i.e. without mouse clicks).
    When the title "Panel 1" gets focused, users can go to "Panel 2" by the right arrow key. When Panel 2 is brought up, however, the title "Panel 2" does not get focused. Instead the first button inside panel 2 is focused. In order for users to navigate to 'Panel 3" by the arrow key, the title "Panel 2" has to be focused. How do I set focus on the tab title?
    I have tried 'requestFocus()' on Panel 2, but it does not work. Please help me with this issue. Thanks in advance.

    I'd be quite interested to know if this can be doen as well so I thought I'd post this message to move it to the top of the board.
    Thanks.

  • How to set focus on a custom PO Item screen field when in error?

    Hi All,
    I have an interesting situation that i'm wondering if others have solved.  We have extended the PO item table (EKPO) by adding two new fields.  We then have implemented two BAdI's:  ME_GUI_PO_CUST and ME_PROCESS_PO_CUST to add them to the ME21N/ME22N/ME23N screens and logic to do some validation, via these respective BAdI's mentioned.  Everything works perfectly - with one small issue.  When we are doing some validation via a method on the ME_PROCESS_PO_CUST - and "invalidate" the field (and throw an error) when it is in error - I also want to be able to "set focus" on the field in question (basically: go to the particular tab on the ME* screen and highlight the field).  I have tried using SET CURSOR FIELD *****  within this BAdI (ME_PROCESS_PO_CUST) - but doesn't seem to work.  Has anyone tried to do this and have come up with a solution?  Would be much appreciative if you shared it!!!  Thanks much.
    Cheers,
    Matt
    ERP version that we have is:  ECC 6.0

    Just have a look at oss note 310154 - ME21N/ME51N: Customer-specific check, generating error log.
    In short:
    Add your error messages in EXIT_SAPMM06E_012 (using specific macros).
    Sample code (provided in Oss note) :
      loop at tekpo where knttp eq 'X'.
        loop at tekkn where ebeln eq tekpo-ebeln and
                            ebelp eq tekpo-ebelp and
                            kostl eq space.
          if not tekkn-id is initial.
            mmpur_business_obj_id tekkn-id.
            mmpur_metafield MMMFD_ACCOUNTINGS.
          endif.
          mmpur_message_forced 'E' 'ZE' '777' '' '' '' ''.
        endloop.
      endloop.

  • How to set focus in text box at server side

    Hi,
    I have small problem , i have a text box in form , which is get validated at server side in servlet , if it found some thing wrong then it throws exception , i want that when an exception is thrown it should set focus for that perticular text box. so what should i write to perform such a activity.

    Get hold of the element ID in the servlet (and keep the code conventions) and print it out to some Javascript function which does a focus during the onload.
    There's an example of focus/highlight using JSP/Servlet/Javascript in this article: [http://balusc.blogspot.com/2008/07/dao-tutorial-use-in-jspservlet.html]. Also see the screenshots at the very bottom.

  • How to set a dynamic textfield?

    How to set a dynamic textfield that can baseon the user input data to resize the textfield height and width? Beside, I would like to copy the MS word table into the Form textfeild with the original design, how to do that? Many thanks!

    You need to check two things:
    1- Make sure to check the "Allow Multiple Lines" under the object tab.
    2- Check the Expand to Fit checkboxes under the layout tab.
    Jasmin

Maybe you are looking for

  • Updated to S.Leopard, now peripheral drive that WAS bootable no longer is.

    I was booting into Tiger OS from my little G3 Mac laptop via an external drive.. worked great. The little G3 laptop will still boot from this external without difficulty. BUT In the meantime, i've updated this iMac to Snow Leopard, and the external (

  • How to rip dvd's with newest MacBook Pro?

    Hi, what is the best application to rip dvd's (with the latest MacBook Pro)? I want to save them and then edit in iMovie. I've seen that Handbrake isn't suitable for 10.8.2 anymore. Thanks!!

  • Passing values to session variables from another application

    Hi, From an external application we are passing username and password for accessing the OBIEE Dashboard.In the url call we are passing NQUser and NQPassword. This is working fine. To setup data level security we need to pass region id list also as re

  • Safty stock level

    HI Gurus , I was just wondering if I I could get any assistance from you for following , I have the following scenario that i have a question for. Safety stock is set at 140 units Actual stock is at 150 units An order was placed for 20 units. As the

  • JAVA_HOME running tomcat

    hi! i recently downloaded the Java Web Services Developer pack. the installation went fine, howeve when i try to run tomcat it gives me Bad command or file name The JAVA_HOME environment variable is not defined This environment variable is needed to