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())

Similar Messages

  • How to set focus on a jsf component of portlet based web page ?

    Hi,
    I have a jsf based portlet in a Websphere Portal environment. I have seen the javascript code document.getElementId(form.component).focus for the attribute onLoad in body tag of a page
    But in a portlet page, the body tag is somewhere in the Head page of the portal.
    How do I achieve this in another way? Is there that accesskey attribute for a component help me to set the focus on itself? HOw do I do that? Any help is appreciated
    Thanks

    Don't put it in the body. Put it below in the code, right before the closing body tag.
    Example<f:verbatim>
        <script>
            setFocus('</f:verbatim><h:outputText value="#{myBean.elementIdToFocus}" /><f:verbatim>'); // load on every view
            function setFocus(elementId) {
                var element = document.getElementById(elementId);
                if (element && element.focus) {
                    element.focus();
        </script>
    </f:verbatim>Where MyBean.getElementIdToFocus() returns the UIComponent.getId().

  • How to set focus on a specific component in an ADFT application

    Hello all,
    We are developing ADFT applications for telnet devices using ITS. Is there any way to set the focus on a specific
    gui component (input text for example) for telnet devices.
    Thanks

    You can use the initialFocusId attribute in the af:document tag. Set this to the id of the component which you want to gain focus.
    It can be a bit tricky if the component is in a table or some other "naming container" because then the actual id for the rendered component is generated (e.g. it may be mytable:0:myinputtext).

  • How to set focus to required component in the application

    Hi all,
    Based on user events, I want to set focus dynamically to required component/panel in the application.
    Is this possible? is yes, pls give me api for that!

    [http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JComponent.html#requestFocusInWindow()]
    A panel is not focusable by default.
    If you want a panel to get the focus you have to use panel.setFocusable(true) first.

  • How to set up  Planning on Multiple Servers

    Hi,
    1) I am trying to install a Finance Planning application so that it runs on one Planning Web Server and the other operations Planning application on another Planning 9.3.1 web server. Is that possilbe?
    2) May be unrelated question:
    HP_Windows_Install.pdf has only a few lines explaining how to set up Planning on Multiple Servers. Is it as simple as that?
    Here are the "few lines" from install.pdf:
    Perform the same installation and configuration process on your secondary servers, making sure to choose
    Planning Web Server component for any secondary server.
    Make sure you select Reuse existing tables when prompted during the Configure a Database task
    in the Configuration utility.

    Tomcat.
    But it will be nice to know the steps for Weblogic too - as Weblogic will be bundled "free" with future releases of Planning.

  • Setting focus to a jsf component inside a tab.

    Hi,
    How can I set focus to a jsf component that is placed on some tab other then the first. Suppose that on the 2nd tabitem of the tab. there are some components on this tab . How can I set the focus to any one of these components on tabitem2 when the jsf page is opened.
    Any ideas..
    Thanks in advance..

    Use Javascript.var el = document.getElementById('elementId');
    if (el && el.focus) {
        el.focus();
    }

  • How to set a delay on Autocomplete component?

    How to set a delay on Autocomplete component so that the completion method will only be invoked when users stop typing for some time. Otherwise, there are too many unnecessary server requests.

    Hi,
    You can use shortDesc property. Something like
    <af:commandToolbarButton text="Some Button"
          id="ctb1" shortDesc="This button does something.."/>-Arun

  • How to set focus on UI Element

    Hi All,
    I am using the below code to set the focus on the first row of the table given in the link  [How to set focus at UI element ? ] on enter of an event.
    data: lr_elem type ref to if_wd_view_element.
    lr_elem = view->get_element( <ID of the Link to Action field>).
    if lr_elem is bound.
    view->request_focus_on_view_elem( lr_elem ).
    endif.
    I am getting "Cannot use NULL reference as object error at view".
    Can you please tell me how to get the reference of the "view".
    Thanks
    Praveen

    >
    praveenkumar_81 wrote:
    > Hi All,
    >
    > I am using the below code to set the focus on the first row of the table given in the link  [How to set focus at UI element ? ] on enter of an event.
    >
    >
    data: lr_elem type ref to if_wd_view_element.
    > lr_elem = view->get_element( <ID of the Link to Action field>).
    >
    > if lr_elem is bound.
    > view->request_focus_on_view_elem( lr_elem ).
    > endif.
    >
    > I am getting "Cannot use NULL reference as object error at view".
    >
    > Can you please tell me how to get the reference of the "view".
    >
    > Thanks
    > Praveen
    Hallo Praveen,
    have you controlled that id of the Linktoaction ? there you made error.
    See it in the ViewElement designer .
    should be something like this
    lr_elem = view->get_element( 'LTA_name ' ).

  • How  to set focus on next row inputfield in table

    Hello all,
    How  to set focus on next row input field in table
    Please help.
    Thanks in advance.
    CSP

    Hi,
    use the following code
    wdThis.wdGetAPI().requestFocus(nodeElement, attribute)
    Ex:
    Provide the attribute and replace the nodeElement with that of yours
    IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute("Your attribute");
           wdThis.wdGetAPI().requestFocus(wdContext.currentContextElement(), attributeInfo);
    Regards
    Ayyapparaj

  • How  to set focus on an element inside a datatable on load

    How to set focus on an element inside a datatable on load

    Check out https://blogs.oracle.com/groundside/entry/ever_wondered_how_uncommitteddatawarning_works and
    Decompiling ADF Binaries: Checking for dirty data
    Timo

  • How to set focus on the last row of JTextPane

    how to set focus on the last row of JTextPane?
    import javax.swing.*;
    import javax.swing.text.html.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MyGUITest extends JPanel implements ActionListener
    {   public static void main(String[] args)
        {   SwingUtilities.invokeLater(new Runnable()
             {   public void run()
              {    JFrame f = new JFrame("My GUI");
                  MyGUITest GUI = new MyGUITest();
                  GUI.setOpaque(true);
                  f.setContentPane(GUI);
                  f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  f.pack();
                  f.setLocationRelativeTo(null);
                  f.setVisible(true);
        JTextPane txtP;
        JButton add;
        HTMLEditorKit hek;
        HTMLDocument hd;
        String txt;
        MyGUITest()
        {     this.setLayout(new BorderLayout());
         this.setPreferredSize(new Dimension(400,200));
         txtP = new JTextPane();
         txtP.setEditable(false);
         txtP.setContentType("text/html");
         txtP.setText("");
         hek = new HTMLEditorKit();
         txtP.setEditorKit(hek);
         hd = new HTMLDocument();
         txtP.setDocument(hd);
         JScrollPane sTxtA = new JScrollPane(txtP);
         add = new JButton("add");
         add.addActionListener(this);
         sTxtA.setBorder(BorderFactory.createTitledBorder(""));
         this.add(sTxtA, BorderLayout.CENTER);
         add(add, BorderLayout.SOUTH);
         new Thread(new Runnable()
         {   public void run()
             {   while(true)
              {   try
                  {     Thread.sleep(100);
                  }catch(InterruptedException ex)
                  {     ex.printStackTrace();
                  appendText("This is <b>HTML</b> text");
                  //add.doClick();
         }).start();
        public void actionPerformed(ActionEvent e)
        {     txt = "<b>asd</b>";
         try
         {   hek.insertHTML(hd, hd.getLength(), txt, 0, 0, null);
         }catch(Exception ex){   ex.printStackTrace();   }
        public void appendText(String txt)
        {     try
         {   hek.insertHTML(hd, hd.getLength(), txt, 0, 0, null);
         }catch(Exception ex){   ex.printStackTrace();   }
    }thanks~

    anIdiot wrote:
    im not sure what is the caret location...So don't youthink you should have looked for it in the API?
    anyway, i want the scroll bar to scrolled down automatically when the output is displayed.
    normally, the scroll bar is scrolled down automatically when a new text is inserted, but it doesnt work on this timeGo through camockr's http://tips4java.wordpress.com/2008/10/22/text-area-scrolling/
    db

  • How to set focus programmatically in a table ?

    Sir,
    How to set focus programmatically in a table using javascript?
    Is it document.getElementById('form1:table1:i:column1').focus(); ?
    Thanks
    Stephen

    Repost

  • Focus on a particular component in the frame

    How to put focus on a particular component example jTextField
    or jComboBox.
    For example:
    when I open the Frame I want the focus to be on jTxtPersonID.
    when I Click the insert button, it inserts a new row, adds today's date in the jTxtOrderDate but after that I want to put
    the focus on jComboBoxPickBook. How to do the focus bit.
    when I select something from jComboBoxPickBook, I want to put
    the focus on jTxtAmt.

    Actually the tab will go the order in which u added ccomponents to the container.
    so if u add in the order no need to write extracode.
    if not just simple in the addkeylistner to the textfield1 and in keypressed write textfield2.requestfoucs();
    textFiled1.addKeyListener (new java.awt.event.KeyAdapter () {
    public void keyPressed(KeyEvent e) {
    jTextField2.requestFocus();
    some thing like this..

  • How to set focus on component guaranteed?

    Hi All,
    I want to run my swing based application on win NT OS with JDK1.5. Now i need to set focus on my JFrame window (this is my requirement) but smetime it focussed and sometime it fails. So i need some guaranteed solution or approach so that it focus on my JFrame window i tried so many methods like requestFocusInWindow(),
    requestFocus(),setFocusable() etc. But my application sometime doing expected behavior and sometime fails.
    Can anybody suggest me 100% guaranteed approach? I appriciate any ideas.
    Regards,
    Pradeep
    Edited by: pradeep_dubey on Mar 17, 2009 6:52 AM

    But my application sometime doing expected behavior and sometime fails.Almost certainly a concurrency issue. Are you aware of Swing's single threaded rule, and have you taken care to create and update all Swing components on the EDT?
    [_Threads and Swing_|http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html]
    [_The Last Word in Swing Threads_|http://java.sun.com/products/jfc/tsc/articles/threads/threads3.html]
    db

  • 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.

Maybe you are looking for