Give focus to a component

Hi,
In my Backing bean code, i change the selected line on my table in a function.
The line is selected but there is no column "focused".
I want the focus to be on the 3rd column of the table...
How can i do this ?
Regards,
Julien

chk
How to focus on an ADF component using a javascript
http://blogs.oracle.com/jdevotnharvest/entry/how_to_set_the_initial_component_focus

Similar Messages

  • Can someone explain how to set the focus to a component

    Hello,
    What is the best way to ensure that a component gets the focus with code. I have tried requestFocus and requestFocusInWindow and none of them seems to do there work. The frame containing the components that should get the focus is displayed, the component is focusable so that is not the problem. What I found out is that if the component is deep in a nesting of panes (where the top pane is in the frame) is that calling requestFocus or requestFocusInWindow does not give the component where this focus is called on the focus but either the pane that contains it, one of the parent panes of this pane or one of the components in these panes, in almost all cases the component requesting the focus does not get the focus at all. I always have to write a work around in defining a focus listener for all these panes that transfer the focus back to the component that requested the focus originally, I can't believe that this is the way to ensure that a component has the focus via code. I have searched for documentation but found nothing on what requestFocus(inWindow) is actually dooing (a lot about focus traversibility but I don't want to control this, just make sure that a component gets the focus).
    Again I'm pretty sure that the toplevel window is activated and that the component that requested the focus is focusable (I had created a derived version of the DefaultFocusManager that showed who has focus). Personally I think (and I'm not alone if you do a search in this forum on focus management) that there is either a big problem in the documentation of focus management or that it is still not possible to even try to set the focus on a component in a easy way.
    Marc

    Hello,
    thanks for your reply, here is some example code that illustrates the problem I have (the actual code is to big to show here, which is the raison why I did not posted it here). The code wil create a frame with a JPanel with a JTextField, a 'New' Jbutton and a 'Delete' Jbutton, a tabbed pane in the center ('New' will create a new JPanel, add it to the tabbed pane and set the focus on it, either by calling RequestFocusInWindow() directly or by calling it via InvokeLater (someone on this forum suggested to use this). I changed also the focusmanager to show the component that has the focus when you type something. To test compile and run the program (either with a call to requesteFocusInWindow directly or indirectly (by changing the comments), on my system I get the following behaviour:
    1. requestFocusInWindow called directly
    Start program en type, the tabbed pane has the focus
    Press New and type something, a button has the focus not the created panel
    Press New again and type something, a button has the focus not the created panel
    2. requestFocusInWindow be called indirectly
    Start program and type, the tabbed pane has the focus
    Press New and type, the created panel has the focus (I thought at one moment that I had found the solution there, but alas ...)
    Press New again and type something, a button has again the focus.
    Note that with my real program it is not always a button that will have the focus, sometimes it is a combobox or a TextField (I tried to get this with the example code (the JTextField) but did not succeed.
    Hopes this clarify the problem a little bid, what I want is when the window is visible to set focus on newly created panes (or in the real program on the panel that is selected via the tabbed pane or via a key combination to shift the focus between the panels) but requestFocusInWindow seems to behave unpredicatable. I can't imagine that what I see is a bug so I must make some assumptions which are not valid but I don't see them, btw listening on the WindowListener is I think not the solution because the frame is already displayed when I want to set the focus and I do not use a modal dialog box.
    The example code follows here
    Marc
    * Main.java
    * Created on December 21, 2004, 8:58 AM
    package testfocus;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    * @author marc
    public class Main
    static int counter;
    /** Creates a new instance of Main */
    public Main()
    * @param args the command line arguments
    public static void main(String[] args)
    JFrame frm=new JFrame();
    JPanel content=new JPanel();
    frm.setContentPane(content);
    final JTabbedPane paneContainer=new JTabbedPane();
    JPanel bar=new JPanel();
    JButton create=new JButton(new AbstractAction("New")
    public void actionPerformed(ActionEvent ev)
    counter++;
    final JPanel pnl=new JPanel();
    pnl.setName("test"+counter);
    paneContainer.add(pnl);
    pnl.setFocusable(true);
    pnl.requestFocusInWindow();
    /* Either use this or the previous line
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    pnl.requestFocusInWindow();
    JButton delete=new JButton(new AbstractAction("Delete")
    public void actionPerformed(ActionEvent ev)
    int i=paneContainer.getComponentCount()-1;
    if (i>=0)
    paneContainer.remove(i);
    JTextField dummy=new JTextField("Test");
    bar.add(dummy);
    bar.add(create);
    bar.add(delete);
    content.setLayout(new BorderLayout());
    content.add(bar,BorderLayout.SOUTH);
    content.add(paneContainer,BorderLayout.CENTER);
    frm.setSize(300,400);
    FocusManager.setCurrentManager(new DefaultFocusManager()
    public void processKeyEvent(Component component,KeyEvent ev)
    System.out.println("Focus owner"+getFocusOwner());
    super.processKeyEvent(component,ev);
    frm.setVisible(true);
    }

  • How to programmatically bring focus to a component

    How can i programmatically bring focus to a component

    [url http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Component.html#requestFocus()]myComponent.requestFocus()

  • Giving focus to a component

    Hi all,
    How does one give focus back or just plain giving focus to a JComponent
    e.g. JTextField, JButton, etc.
    This puzzles, me please help?

    That method was introduced in 1.4, but the API recommends you use requestFocusInWindow()

  • How to set Focus for one component on Dialog

    Hi all.
    I have a problem and need a help
    I have a JDialog
    I add some components on it. Includes button, textfield...
    after i set
         _textField.requestFocus()When Dialog show, it always focus at first component, not at the component i set.
    Please help me.
    Thanks in advance
    Diego

    Perhaps Swings threading ruins your focus request, and trying invokeLater may be worthwhile...
    Note that [requestFocusInwindow()|http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#requestFocusInWindow()] is to be preferred over requestFocus according to the API docs.
    Edited by: isocdev_mb on Mar 4, 2010 6:05 AM

  • JDev11 : programmatically give focus to a page component

    Hello ,
    I have some richTextEditors in a JSF page. When I press <ctrl+space>, a bean is called to seek an abreviation and if it find it it refresh the component
    RequestContext.getCurrentInstance().addPartialTarget(rte);
    // rte is a richTextEditorWhen my richTextEditor's value is refreshed, it lose focus. Is it possible to give it back this focus ?
    thanx,
    Valéry.

    Hi,
    what about storing the component content area in a JavaScript variable and then setting the focus back. Question only is if you can receive end of refresh notification for executing it
    Frank

  • Give sole focus to a component

    I would like to have a JDialog always maintain focus and prevent any action to other components (eg. menu items, and mouse listener in other components).
    I tried adding a WindowFocusListener to the JDialog and having it call requestFocus() in windowFocusLost(), but that did not seem to solve the problem.
    I also have a JPanel (the is underneath the JDialog) that also calls requestFocus() whenever there is mouse motion (because to it has a keyboard listener). But even without the requestFocus(), the mouse listener in the JPanel is still reponding to actions.

    You want to use a [url http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html#overview]modal dialog

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

  • 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

  • In Flash CS4,How can I give a AS3 List Component a suitable horizontalScrollBar

    In Flash CS4 when an AS3 List Component has too many rows,it will has a verticalScrollBar automatically. but it will never has a horizontalScrollBar even a part of the content of the list is hidden.
    I set the property  list.horizontalScrollPolicy="on",and set list.maxHorizontalScrollPosition=200; then the horizontalScrollBar appear
    but when I click the item of the list, all the list move to left, half of the list is hidden,
    I can only see the right part of the list, the I click the list again,the list move to right,then I can see all the list by move the horizontalScrollBar
    How can I give a suitable horizontalBar to the AS3 list component?

    Thank you for your help! (sorry,I`m bad in English...)
    In fact, it works.
    but,I made a mistake,the reason I want to give a list a horizontalScrollBar is:I want to show all content in a list that is not wide enough,
    you see,first row can show all content in this list,but in the other rows,the content is too wide to show,I want to give the list a horizontalScrollBar to show all content by draging the horizontalScrollBar to right.
    now,set property:
    list.horizontalScrollPolicy="on", list.maxHorizontalScrollPosition=30;(the result is the image above),when I drag the horizontalScrollBar to right:
    ah ha ,the row can`t show all content too,the horizontalScrollBar is related to the width of all the list, is not related to the width of the content in every row.
    now I kown why the horizontalScrollBar is always disable.
    but in design,to show a lot of content,we can`t draw  a list too wide, it`s not beatiful,so I want to use a horizontalScrollBar to show all content in every row.
    and the list is not too wide
    ah ah,  like the list in Flex4
    In fact,ah,I have not studied Flex 4,so,I have to make it by using Flash CS4 Component
    How can I do? Please
    (so sorry for my bad English,I do my best in it)

  • Focus cell editor component of JTable when starting editing by typing

    Hello, everybody.
    We all know that the JTable component doesn't actually focus the actual cell editor component when editing is started by typing. But I need this functionality in an application of mine. So, I ask: is there a way to transfer focus to the editor component when editing is started by typing?
    Thank you.
    Marcos

    Well, I think that I've found it: JTable#setSurrendersFocusOnKeystroke.
    Marcos

  • Focus the third component after the current focus owner

    Hi,
    I have a component which consists of a textfield with two buttons right of it. I have several of these components placed on a panel. I want, when enter pressed, the focus moved from a textfield, to the second textfield in line. I tried this by calling
    KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent();three times but after going to 1 focusNextComponent it stops. Visually, it goes to the next but when I call
    KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    it is 1 step behind. Do I have to update anything when calling focusNextComponent()?
    Much thanks,
    Hugo

    Will this help?
    Execute the programme and press enter and the focus is gone to the third component.
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class FocusTest extends JFrame implements KeyListener
         JTextField jtf1,jtf2,jtf3;
         JPanel p;
         public FocusTest()
              jtf1 = new JTextField(10);
              jtf2 = new JTextField(10);
              jtf3 = new JTextField(10);
              jtf1.addKeyListener(this);
              p       = new JPanel();
              p.add(jtf1);
              p.add(jtf2);
              p.add(jtf3);
              getContentPane().add(p);
         public static void main(String dd[])
              FocusTest ft = new FocusTest();
              ft.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              ft.setSize(200,200);
              ft.setVisible(true);
         public void keyPressed(KeyEvent ke)
              if(ke.getKeyCode() == KeyEvent.VK_ENTER)
                   System.out.println("ll");
                   jtf3.requestFocus();
         public void keyReleased(KeyEvent ke)
         public void keyTyped(KeyEvent ke)
    }

  • How to manage focus in custom component

    Hallo. As you know some flex components have native focus, like buttons, textinput etc.. I have created a custom component which is a borderContainer.. As you know, by default, if user press TAB my BorderContainer will never receive the focus.. I tryied to set some property like setFocus() and tabFobusEnabled to true but i still have some focus problems with my borderContainer .. It is like my App knows that my Custom component is not a native component.. Is there a way for my component to receive focus without problems??.. Which is the best way for doing that??
    Thx a lot
    Max

    Components must implement IFocusManagerComponent in order to receive focus.

  • WHEN-WINDOW-ACTIVATED gives focus back to applet window

    Testcase:
    Form A calls form B
    Form B performs this code:
    BEGIN
    web.show_document(url);
    exit_form;
    END;
    This should open a new browser window to the URL and keep the focus on it.
    However, when form A has a WHEN-WINDOW-ACTIVATED trigger (even when the only code is NULL;), it return the focus to the forms applet browser window the first time.
    This is very annoying because the new browser window can no longer be seen as it is put on the background. Strangly enough, the following times the focus remains on the new browser window.
    Is this a known bug?
    PS: The problem is that i really need a WHEN-WINDOW-ACTIVATED trigger in my form A to perform some webutil-functions.
    Environment:
    Forms Developer 10g Release 2
    Application Server 10g Release 2
    Window 2000/Xp
    Oracle Jinitiator 1.3.1.22

    In which trigger are you calling Form B? As I said, the EXIT_FORM event would take you back to Form A after opening the browser window, so what happens next depends on what code it fires once returning to Form A.
    Have you tried it with debug messages on to see what triggers it is firing? (both first time round & subsequently). Logically, I would have actually expected focus to return to Form A following the EXIT_FORM, but maybe I'm wrong ni thinking that.
    Have you experimented with the various WEB.SHOW_DOCUMENT options (e.g. WEB.SHOW_DOCUMENT(url, '_self') to get a different behaviour?

  • How to set focus on a Component?

    I'm doing a simple DATA ENTRY program. My web apps contains the ff:
    - 4- buttons (add, save, undo, del)
    - table
    To avoid mistakes on the data entry by a user. I make it a point to limit possible areas of risk. Like:
    ie: when addButton is clicked.
    - we set addButton.setDISABLED(true)
    - also we set delButton.setDISABLED(true)
    Problem: On the web browser, we get an error that saysn "Can't move to the focus control ... blah, blah blah"
    How do I set the focus on other control?

    I suppose this is a javascript error.
    If you are using firefox, could you please add what the error is that you are seeing.
    How are you trying to set the focus on the other button?
    You could try adding javascript code to onclick functionality of the button you are disabling.
    something like:
    onclick = "<client id of the button to have focus>.focus()";

Maybe you are looking for