Default Focus on textInput ?

Hi everybody !
How set default focus on form element ?

Hi Rustam -
I believe that you'll need to write a bit of JavaScript to do this. You can set the default focus in your body's onLoad handler. Here is a sample uiXML page which sets the focus to a text input control when the page is loaded:
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://xmlns.oracle.com/uix/controller"
      xmlns:ui="http://xmlns.oracle.com/uix/ui"
      xmlns:data="http://xmlns.oracle.com/uix/ui"
      xmlns:ctrl="http://xmlns.oracle.com/uix/controller">
<content>
  <body onLoad="form1.text2.focus()" xmlns="http://xmlns.oracle.com/uix/ui">
  <contents>
    <form name="form1">
    <contents>
      <stackLayout>
      <contents>
        <textInput name="text1"/>
        <textInput name="text2"/>
      </contents>
      </stackLayout>
    </contents>
    </form>
  </contents>
  </body>
</content>
</page>Andy

Similar Messages

  • In Flex,how to make lost focus of textinput on enter click?

    Hi
    In Flex,how to make lost focus of textinput on enter click of keyboard ?
    Thanks,
    Sunil

    Hi vibhuti,
         I  got your point but it will not helpful to me.
        But I found solution ,When user clicks enter key make stage.focus = null  so it will lost focus on text input and make focus in my current Alert Box.
    Thanks,
    Sunil

  • [Flex 4.5.1] Focus on TextInput hides windows 7 language bar when in Chrome, Firefox works fine

    Focus on TextInput hides windows 7 language bar when in Chrome (latest version by the time of the writting) - very odd behavior, if the user clicks away from the flex app then the language bar reappears but even if you change the language if you focus back on the application the language is back to what it was the last time the application was focused, though you can't actually see this since the language bar is gone.
    This is kind of a serious bug since an avarage user probably would't be able to change the language with key combinations...
    Does someone know anything about this issue ?

    Actually giving focus on the entire flex application results in hiding the windows 7 language bar in chrome. I just reported this. Here is the link for the bug + an extra issue:
    http://bugs.adobe.com/jira/browse/SDK-32039

  • Default Focus on TextField

    Hello All,
    I have got a problem, please help me. I have a textfield in a frame. When call that frame the textfield will be displayed with default focus on it. I dont want to have the cursor in that text field. I dont have any other swing components in that and the text field is the first component in that frame.
    Please help me....
    Thanks in advance

    Hello
    Thanks for your reply. But i my code is some thing like this.
    public class TextFieldExample extends JFrame
         public JTextField textField;
         public JButton enterButton;
         public TextFieldExample()
              super();
              textField = new JTextField(25);
              JPanel jp = new JPanel();
              jp.add(textField);
              getContentPane().add(jp);
              setLocationRelativeTo(this);
              pack();
         public static void main(String args[])
              TextFieldExample textFieldExample = new TextFieldExample();
              textFieldExample.setVisible(true);
              textFieldExample.addWindowListener(new WindowAdapter()
                   public void windowClosing(WindowEvent we)
                        System.exit(0);
    Now Please suggest me the solution.

  • Is there a default focus Method ?

    I would like to have a button to be focused by default within a dialog such that user can easily fire the button's action. Is there a method to set default focus on a button ? Thanks !!!

    That's actually very helpful. I can now set a default focus button on a dialog. But then for some reason I can not set it for other dialogs initiated by this dialog. Since I have an opening dialog with a number of buttons, and those buttons will open up a new dialog. Right now I can only set the default focus to the opening dialog. The other dialogs that opens up from firing the buttons did not have the same effect as the opening dialog. Is there a way to fix it ? Thanks

  • Default focus behavior in Swing

    I have a JTabbedPane wherein every tab has a variety of fields, including buttons, text areas, text fields, tables, and so on. I wanted to tweak the default focus behavior such that the first text field or the first text area has the focus.
    I used requestFocusInWindow() to set the focus on the first text field I get. This, however, was being overriden at a later stage (I am working on a vast code) and the first component inside a tab is getting the focus.
    Is there any means to override the default focus behavior? I tried writing my own FocusTraversalPolicy but found that that is never used. How does the default focus behavior work? Does it set the focus on the first field it gets or what? And where can I find the code for the same?

    I used requestFocusInWindow() to set the focus on the first text field I get. The requestFocusInWindow() method only works when the GUI is already visible. So I would suggest that you add a ChangeListener to the tabbed pane and add your code to set the focus every time the tab is changed.
    For a slightly different approach the code in this posting will remember the last field for each tab that had focus and reset focus to that field when the tab is changed. The code is not completely off topic since it shows how to use a ChangeListener:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=570369

  • Changing the application wide default focus traversal policy

    Hi,
    I have a Swing application built using JDK1.3 where there lots of screens (frames, dialogs with complex screens - panels, tables, tabbed panes etc), in some screens layouts have been used and in other screens instead of any layout, absolute positions and sizes of the controls have been specified.
    In some screens setNextFocusableComponent() methods for some components have been called at some other places default focus traversal is used. (which I think is the order in which the components are placed and their postions etc). Focus traversal in each screen works fine.
    Now I have to migrate to JDK1.4. Problem now is that after migrating to JDK1.4.2, focus traversal has become a headache. In some screens there is no focus traversal and in some there is it is not what I wanted.
    So I thought to replace applicaiton wide default focus traversal policy and I did the following:
    ///////// Replace default focus traversal policy
    java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalPolicy(new java.awt.ContainerOrderFocusTraversalPolicy());
    But there is no change in the behaviour.
    Then I tried following:
    ///////// Replace default focus traversal policy
    java.awt.KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalPolicy(new java.awt.DefaultFocusTraversalPolicy());
    I did all this in the main() method of the application before anything else just to ensure that all the components get added after this policy has been set. But no luck.
    Does someone has any idea what is the problem here ? I do not want to define my own focus traversal policy for each screen that I use (because thats lot of codes).
    Thanks

    not that hard if you only have the one focus cycle ( > 1 cycle and it gets a bit harder, sometimes stranger)
    import javax.swing.*;
    import java.awt.*;
    class Testing
      int focusNumber = 0;
      public void buildGUI()
        JTextField[] tf = new JTextField[10];
        JPanel p = new JPanel(new GridLayout(5,2));
        for(int x = 0, y = tf.length; x < y; x++)
          tf[x] = new JTextField(5);
          p.add(tf[x]);
        final JTextField[] focusList = new JTextField[]{tf[1],tf[0],tf[3],tf[2],tf[5],tf[4],tf[7],tf[6],tf[9],tf[8]};
        JFrame f = new JFrame();
        f.setFocusTraversalPolicy(new FocusTraversalPolicy(){
          public Component getComponentAfter(Container focusCycleRoot,Component aComponent)
            focusNumber = (focusNumber+1) % focusList.length;
            return focusList[focusNumber];
          public Component getComponentBefore(Container focusCycleRoot,Component aComponent)
            focusNumber = (focusList.length+focusNumber-1) % focusList.length;
            return focusList[focusNumber];
          public Component getDefaultComponent(Container focusCycleRoot){return focusList[0];}
          public Component getLastComponent(Container focusCycleRoot){return focusList[focusList.length-1];}
          public Component getFirstComponent(Container focusCycleRoot){return focusList[0];}
        f.getContentPane().add(p);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }

  • JOptionPane en default focus issues

    Hello,
    I have written a simple class to show a login dialog, but I can't get the default focus right. My problem is that I want the first JTextField (usernameField) to be the one select when my dialog shows, but I want the first button (Ok button) to be called automatically when I press enter. What happens now that I set the first button (Ok button) default (last argument of JOptionPane.showOptionDialog), this makes sure that whenever I press enter this buttons gets called en the dialog reacts accordingly. But when the dialog is first shown this default button is also the one selected (having focus), this is not what I want. The JTextField (usernameField) should be selected (have focus) so a user can enter his username, then press enter and see what happens.
    When I don't set a default button nothings happens when I press enter but now the right JTextFields (usernameField) is selected.
    Hope anyone can help me.
    Thank you very much.
    The code:
    public class LoginDialog
        private int attempts;
        private TargetFinder controller;
        private Component parent;
        private String username;
        private String password;
        public LoginDialog(TargetFinder controller, Component parent)
            this.controller = controller;
            this.parent = parent;
            username = "";
            password = "";
        private int buildDialog()
            String dialogTitle, usernameText, passwordText, errorPart1, errorPart2;
            String[] buttonsText;
            try
                dialogTitle = LanguageParser.getText("loginTitle");
                usernameText = LanguageParser.getText("username");
                passwordText = LanguageParser.getText("password");
                buttonsText = new String[2];            
                buttonsText[0] = LanguageParser.getText("loginTitle");
                buttonsText[1] = LanguageParser.getText("cancel");
                errorPart1 = LanguageParser.getText("loginError1");     
                errorPart2 = LanguageParser.getText("loginError2");
            catch (Exception e)
                throw new RuntimeException("Login dialog could not be created", e);
            JPanel namePanel = new JPanel(false);
            namePanel.setLayout( new GridLayout(0, 1) );
            namePanel.add( new JLabel(usernameText) );
            namePanel.add( new JLabel(passwordText) );
            JPanel fieldPanel = new JPanel(false);
            fieldPanel.setLayout( new GridLayout(0, 1) );
            JTextField usernameField = new JTextField(12);
            fieldPanel.add(usernameField);
            JPasswordField passwordField = new JPasswordField(12);
            fieldPanel.add(passwordField);
            JPanel componentPanel = new JPanel(false);
            componentPanel.setLayout( new BoxLayout(componentPanel,
                    BoxLayout.X_AXIS) );       
            componentPanel.add(namePanel);
            componentPanel.add(fieldPanel);
            JPanel componentPanelError = new JPanel(false);
            componentPanelError.setLayout( new GridLayout(0, 1) );
            componentPanelError.add(componentPanel);
            JLabel errorLabel = new JLabel(
                    "<html>" +
                    errorPart1 +
                    "<br>" +
                    errorPart2 +
                    "</html>" );   
            errorLabel.setForeground(Color.RED);
            componentPanelError.add(errorLabel);
            int res;
            res = JOptionPane.showOptionDialog(
                    parent,
                    (attempts == 0) ? componentPanel : componentPanelError,
                    dialogTitle,
                    JOptionPane.OK_CANCEL_OPTION,
                    (attempts == 0) ? JOptionPane.INFORMATION_MESSAGE : JOptionPane.ERROR_MESSAGE,
                    null,
                    buttonsText,
                    buttonsText[0] );
            if (res == JOptionPane.OK_OPTION)
                username = usernameField.getText();
                password = new String( passwordField.getPassword() );
            return res;
        public boolean login()
            attempts = 0;
            Database database = controller.getDatabase();
            while ( buildDialog() == JOptionPane.OK_OPTION )
                if ( database.login(username, password) )
                    return true;
                attempts++;
            return false;
    }

    Thanks for your reaction Olek,
    But I can't request focus because JOptionPane creates a model window, so the JVM waits for the user to click one of the buttons.
    Also I don't know how to add a ButtonListers to any of the buttons because the are created dynamicly by JOptionPane.
    I use JOptionPane.OK_CANCEL_OPTION to create both an Ok and a Cancel button, and define an array (buttonsText) with names for them. I can't ask the rootPane for this buttons because they only excist after I call JOptionPane.showOptionDialog(...) and this is model window.
            int res;
            res = JOptionPane.showOptionDialog(
                    parent,
                    (attempts == 0) ? componentPanel : componentPanelError,
                    dialogTitle,
                    JOptionPane.OK_CANCEL_OPTION,
                    (attempts == 0) ? JOptionPane.INFORMATION_MESSAGE : JOptionPane.ERROR_MESSAGE,
                    null,
                    buttonsText,
                    buttonsText[0] );With kind regards,
    Eddy

  • [Flex 4.5.1] How to remove focus from TextInput on mouse click outside of it?

    For me clicking outside of a TextInput should always remove focus from it, only only if you click on another TextInput or Button.
    I don't see any simple event like MouseEvent.MOUSE_CLICK_OUTSIDE - which would definitely simplify things.. I wonder why there isn't such event. Well anyway I can't find any other similar event and I can't figure out an easy way to do this. I also wonder why I couldn't find a solution to this on the web easily... Well anyway...
    Does someone know how to do that in a convenient way?
    Thanks!

    ok I understand why is that. For example I have a TextInput now where the user enters number through buttons which have mouseFocusEnabled = false, so the TextInput doesn't lose focus. But on a TabBar I had to set mouseFocusEnabled = true or when I switched between tabs -> switches between states, I could still type in the TextInput in the previous tab cause it didn't lose focus. Maybe TabBar's default value of that property is wrongly set to false.
    Anyway, not losing focus when clicking outside is still weird. Take for example this forum, if I click outside of the box I am currently writing this, I lose focus. It's how things usually work. And flex focus is designed to work backwards to what people are used to, no matter as I already pointed out I understand there are cases it comes in handly. I hope I don't sound bad but take it just as a suggestion please that maybe if it is redesigned like this: clicking on component gets focus, clicking outside loses focus. But if you click on a button for example and you want to keep the focus on a TextInput cause you add some text, you should be able to set a property on the Button like maintainCurrentFocus = true (false by default), which would make clicking on the Button not shift the focus to it or set it to null if the component is a group that has some rect background for example, but maintain the focus on the TextInput.
    I could be missing something about the current design of how the focus works in flex, but from my point of view at the moment, the design I describe to use is just like how I am usually used to be working with focus as a user, not as developer.
    Maybe you could agree or maybe you know some reason by which things are how they are at the moment that I don't see. But if you think I make sense please let me know, maybe I could fill a minor enhancement request for that ?

  • How to create an YES/NO JOptionPane with the default focus on No?

    Hi,
    can somebody please show me how to display an JOptionPane with the options Yes and No that has the focus by default no the No button?
    By default it is on the Yes button which is rather problematic for confirm dialogs like "Do you really want to delete everything?".
    JPJava

    It would help if JPJava gave some sample code SSCCE to show they know how to construct a JOptionPane
    I use explorer to access the source files in the zip folder and JGrasp to view the source code
    this is copy modify from the API
    Object[] options = { "YES", "CANCEL" };//{"OK", "CANCEL"} shown in api
    JOptionPane.showOptionDialog(null, "Are you sure you want to delete", "Confirm Delete",
    JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
    null, options, options[1]);//options[1] selects CANCEL option as defaultthis method constructs
    showOptionDialog
    public static int showOptionDialog(Component parentComponent,
                                       Object message,
                                       String title,
                                       int optionType,
                                       int messageType,
                                       Icon icon,
                                       Object[] options,
                                       Object initialValue)
                                throws HeadlessExceptionBrings up a dialog with a specified icon, where the initial
    choice is determined by the initialValue parameter and the number of choices is determined by the optionType parameter.
    If optionType is YES_NO_OPTION, or YES_NO_CANCEL_OPTION and the options parameter is null,
    then the options are supplied by the look and feel.
    The messageType parameter is primarily used to supply a default icon from the look and feel.
    Parameters:
    parentComponent - determines the Frame in which the dialog is displayed; if null, or if the parentComponent
    has no Frame, a default Frame is used
    message - the Object to display
    title - the title string for the dialog
    optionType - an integer designating the options available on the dialog: YES_NO_OPTION, or
    YES_NO_CANCEL_OPTION
    messageType - an integer designating the kind of message this is, primarily used to determine the icon from
    the pluggable Look and Feel: ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE,
    QUESTION_MESSAGE, or PLAIN_MESSAGE
    icon - the icon to display in the dialog
    options - an array of objects indicating the possible choices the user can make; if the objects are components,
    they are rendered properly; non-String objects are rendered using their toString methods; if this parameter is null,
    the options are determined by the Look and Feel
    initialValue - the object that represents the default selection for the dialog; only meaningful if options is used; can be null
    Returns:
    an integer indicating the option chosen by the user, or CLOSED_OPTION if the user closed the dialog
    Throws:
    HeadlessException - if GraphicsEnvironment.isHeadless returns true
    See Also:
    GraphicsEnvironment.isHeadless()Edited by: Ross_M on Sep 22, 2008 9:19 AM

  • How to set the default focus to  a particular jtextfield

    hi,
    i'm trying to set the focus to the specified Jtextfield by default.
    i tried with reqestFocus() method,grabFocus() method,getCursor() method
    but all in vain.
    can anyone suggest me a solution please.
    very urgent request please
    thanks in advance
    regards
    Ravi teja

    If I understand the question correctly then this thread will help:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=290339

  • Default Focus to Button

    Hi,
    I have around 10 controls on my JDialog and Edit-F2 (Caption on JButton)
    is one of them. Other components are disabled except the Edit-F2 button.
    Now my Problem is when the Dialog pop's up on Pressing F2 the funtionality
    associated with edit button should be executed. I am unable to set the
    focus of the first time on Edit-F2 button. I tried grabFocus (),
    requestFocus (), requestDefaultFocus (). I have implemented the keylisteners
    also.
    Please help. Thanks in advance.
    -regards
    deena

    Hello,
    There is one important thing to know about Swing and the focus management :
    The focus manager sets automatically the focus on the first component of the Frame that as the focus.
    If this first component is a container, it sets the focus on the first component of this container.
    And if this component is also a container that contains other components, it sets the focus on the first of them.
    Etc...
    So, if you want a button to be the default button of a container, use the add(Component comp, int index), or the add(Component comp, Object constraints, int index) with index set to 0. You should do the same with the parent component of your button. Here is an example with a panel :
       JFrame frame = new JFrame("test") ;
       JPanel panel0 = new JPanel() ;
       panel0.add(new JButton("button 1"));
       panel0.add(new JButton("button 2"));
       JPanel panel1 = new JPanel() ;
       panel1.add(new JButton("button 3")) ;
       panel1.add(new JButton("default button"),0);
       frame.getContentPane().add(panel0) ;
       frame.getContentPane().add(panel1 , 0 );Running this code you should not need to call requestFocus nor any other method to set the focus on "default button".
    Do not forget to set some constraints on your components to layout them correctly...

  • Set default focus on pushbutton (dynpro not ALV)

    Dear all
    I created a popup showing a table control and 2 buttons (confirm / abort).
    The user simply wants to push the confirm button to proceed by pressing enter but unfortunatly I see no way to set the focus on that element by default.
    Any help is appreciated.
    Thank's in advance and best regards
    Benno

    Use this in PBO:
    * BUT_CONF is the button for the Confirm
    SET CURSOR FIELD 'BUT_CONF'
    Regards,
    Naimesh Patel

  • ITunes takes default focus when switching desktops (spaces)

    This is more of a pet peeve than anything, but when I am swiping between desktops (spaces), and I return to my primary desktop, iTunes always takes focus.
    99% of the time, I have switched from my web browser to mail (which I keep in another space) and when I return to open a new tab in the browser, iTunes preferences opens almost every time (command-T).
    I would normally assume, or prefer, that the OS "remember" where I left off when switching spaces, and put me right back there when I switch back.  Is there a way to force this?

    You're totally right.
    I've already tried to find the differences, but not accurately enough. I'll do it again.
    Also, I've noticed another strange thing : even with my rc.lua broken, I have this issue. I think that with a broken rc.lua the default one is used, so it may not come from my configuration. if it doesn't, I have no idea...
    I'll check again the other install and will tell you if I have something (but not before tuesday)
    [Edit]
    I've tried with the default rc.lua, and I indeed still have this issue.
    For now, I have a workaround : I just add a small titlebar to every window, as if they were floating (cf very end of my rc.lua posted above).
    But if someone has any idea to really fix it, I would be happy
    Last edited by nyddogghr (2014-07-12 10:17:31)

  • How to set the default focus component using FocusTraversalPolicy class??

    hi all...
    I have a JPanel, of which setFocusCycleRoot() has been made true. I am trying to make sure that whenever I open this panel, the first JTextField must have the focus.
    the problem is that I have to hit the tab key once, ay satrtuptime. after that all works fine. Kindly rell me a way to eliminate this first-time tab key hitting.
    please note that I have extended FocusTraversalPolicy class and have defined all its methods accordingly....
    thanx...

    try this at the end of your constructor:
    myTextField.requestFocusInWindow();
    it works in my login panel that wants to focus the second password field after i added the panel to the internal frame.

Maybe you are looking for

  • Does not copy correctly

    Printer prints fine off PC...but when I copy, it prints black lines down the page

  • My Skype Crashes at Startup

    hey i dont know the format to post but , my skype keeps crashing at startup was working fine just before today , but now i cant use it

  • What do you think of N86?

    Do you guys think N86's 8MP lense will shoot much better pictures than 5MP Nseries Phones? And how about the Video Recording Quality? Solved! Go to Solution.

  • Safari keeps playing an annoying music in the background.

    I visited youtube couple hours ago and suddenly safari started playing this annoying song in portugese. I cannot stop it. Removed the software, reinstalled it, no good. reset the safari, cleaned history, cache, again no good. Firefox still works fine

  • What happened to my full screen view in iOS7?

    Before I downloaded iOS7 I could rotate my phone to utilize more of the screen. For example, when typing I could rotate my phone for a larger keyboard. Or, to prevent constant squinting I could rotate my phone to view photos and videos full screen. A