Setting focus to tab i JTabbedPane

I have a layout with a tabbed pane within a tabbed pane. I want to to be able to bring a tab to the front from one of the other tabs. I.e. if I have tabs 1 and 2 with two sub tabs in each (1.1, 1.2, 2.1 and 2.2) I want to be able to fire an event in e.g. tab 1.2 that brings tab 2.1 to the front.
/Olle

Just implement somethink like this
      jTabbedPane1.setSelectedIndex(2);
      jTabbedPane2.setSelectedIndex(1);You simply select the tab out of an other tab!!
Gl
Luca

Similar Messages

  • How to set a single tab in JTabbedPane invisible

    Hello,
    I want to set only a single tab invisible out of 9 tabs in JTabbedPane. I can disable the tab but not able to set invisible.
    Thanking you in advance.

    you may use JTabbedPane.removeTabAt(int) method as long as you don't want the tab to appear & when needed use JTabbedPane.insertTabAt(String, Icon, Component, String, int) method.
    as far as i know this is only way to achieve our want. this should help you.
    regards,
    Afroze.

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

  • JTabbedPane - traversing focus through tabs

    I would like to have focus traverse through tabs in a JTabbedPane. That is, when the focus is on the last component of a tab, hitting the key for forward focus traverse should bring up the next tab and focus on the first component on that tab. I'm already using a custom FocusTraversalPolicy on the panel containing the JTabbedPane, which handles focus traversal between the components on the tabs. This policy has no knowledge of which tab a particular component is on.
    I was hoping calling requestFocusInWindow() would automagically focus that tab, but it doesn't. Needless to say, having the focus traversal policy cycle through all the components (including those in non-selected tabs) doesn't work, either. Is there an elegant way to do this, without resorting to listening to key events, watching for the TAB key, and switching to the appropriate tab?

    Ok. here is my suggestion.
    When the focus is going to be transferred to the other tab use tabpane.setSelectedComponent(nextPanel), it will trigger traverse policy once again, but we will catch the fact that current component is JPanel and transfer it further to our field.
    Following code looks ugly:
    order.add(tf1);
    order.add(tf2);
    parentsForward.put(p,tf1);
    parentsBackward.put(p,b2);but this is a concept demonstration only, you can hide this piece inside TraversalPolicy implementation.
    Here is the full code:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class TabbedFocusExample extends JFrame  {
        public TabbedFocusExample()  throws HeadlessException {
            super("Tabbed Focus Test");
            setLayout(new FlowLayout());
            JPanel p;
            final JTabbedPane tp = new JTabbedPane();
            final JTextField tf1 = new JTextField(20);
            final JTextField tf2 = new JTextField(20);
            final JCheckBox cb1 = new JCheckBox("Option 1");
            final JCheckBox cb2 = new JCheckBox("Option 2");
            final JButton b1 = new JButton("Click me!");
            final JButton b2 = new JButton("Press me!");
         //stores real components, no container
         Vector<Component> order = new Vector<Component>();
         //stores (container,first_component_in_this_container) pair
            Map<Component,JComponent> parentsForward = new HashMap<Component,JComponent>();
         //stores (container,last_component_in_previous_container) pair
         Map<Component,JComponent> parentsBackward = new HashMap<Component,JComponent>();
            p = new JPanel(new FlowLayout());
            p.add(tf1);
            p.add(tf2);
            tp.addTab("Tab 1",p);
         order.add(tf1);
            order.add(tf2);
         parentsForward.put(p,tf1);
         parentsBackward.put(p,b2);
            p = new JPanel(new FlowLayout());
            p.add(cb1);
            p.add(cb2);
            tp.addTab("Tab 2", p);
         order.add(cb1);
            order.add(cb2);
         parentsForward.put(p,cb1);
         parentsBackward.put(p,tf2);
            p = new JPanel(new FlowLayout());
            p.add(b1);
            p.add(b2);
            tp.addTab("Tab 3", p);
         order.add(b1);
            order.add(b2);
         parentsForward.put(p,b1);
         parentsBackward.put(p,cb2);
         setFocusTraversalPolicy(new MyOwnFocusTraversalPolicy(order,parentsBackward,
                              parentsForward,tp));
            add(tp);
            pack();
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        public static void main(String[] args) {
            new TabbedFocusExample().setVisible(true);
        public  class MyOwnFocusTraversalPolicy     extends FocusTraversalPolicy   {
         private Vector<Component> order;
         private JTabbedPane tabbedPane;
         private Map<Component, JComponent> parentsForward;
         private Map<Component, JComponent> parentsBackward;
            public MyOwnFocusTraversalPolicy(Vector<Component> order,Map<Component,JComponent> parentsF,
                                       Map<Component,JComponent> parentsB,JTabbedPane jtb) {
                this.order = order;
             this.tabbedPane=jtb;
             this.parentsForward = parentsF;
                this.parentsBackward = parentsB;
            public Component getComponentAfter(Container focusCycleRoot,
                                               Component aComponent) {
              JComponent nextComp = parentsForward.get(aComponent);
              if(nextComp!=null){ //aComponent is Container return first component in this Container
                   return nextComp;
                    int idx = (order.indexOf(aComponent) + 1) % order.size();
              nextComp = (JComponent)order.get(idx);
              int indexCurrent = tabbedPane.indexOfComponent(((JComponent)aComponent).getParent());
              int indexNext = tabbedPane.indexOfComponent(nextComp.getParent());
              if(indexNext!=indexCurrent){ //if next Component sits in next tab go to next tab
                   tabbedPane.setSelectedComponent(nextComp.getParent());
                    return nextComp;
         //same stuff but in opposite direction
            public Component getComponentBefore(Container focusCycleRoot,
                                                Component aComponent)  {
              JComponent prevComp= parentsBackward.get(aComponent);
              if(prevComp!=null){
                   return prevComp;
                    int idx = order.indexOf(aComponent) - 1;
                    if (idx < 0) {
                          idx = order.size() - 1;
                    prevComp = (JComponent)order.get(idx);
              int indexCurrent = tabbedPane.indexOfComponent(((JComponent)aComponent).getParent());
              int indexPrevious = tabbedPane.indexOfComponent(prevComp.getParent());
              if(indexPrevious!=indexCurrent){
                   tabbedPane.setSelectedComponent(prevComp.getParent());
                   return prevComp;
            public Component getDefaultComponent(Container focusCycleRoot) {
                return order.get(0);
            public Component getLastComponent(Container focusCycleRoot) {
                return order.lastElement();
            public Component getFirstComponent(Container focusCycleRoot) {
                return order.get(0);
    }

  • Setting focus to a JTextArea using tab

    Hi,
    I have a JPanel with a lot of controls on it. When I press tab I want to
    move focus to the next focusable component. This works fine for
    JTextFields, but when the next component is a JTextArea in a
    JScrollPane then I have to press tab 3 times to set the focus to the
    JTextArea. After pressing the tab key once I think the focus is set to
    the scrollBars of the JTextArea because when I press the up and down
    arrows the textarea is scrolled.
    How can I stop the JScrollPane from getting the focus?
    I have tried to set focusable to false on the scrollPane:
    scrollPanel.setFocusable(false);
    and the scrollBars of the scrollPane:
    scrollPanel.getHorizontalScrollBar().setFocusable(false);
    scrollPanel.getVerticalScrollBar().setFocusable(false);
    But it dosen�t work. Is this a completely wrong way of doing it?
    Please help!
    I use jdk 1.4.1
    :-)Lisa

    Not sure what your problem is. The default behaviour is for focus to go directly to the JTextArea.
    import java.awt.*;
    import javax.swing.*;
    public class Test1 extends JFrame
         public Test1()
              getContentPane().add( new JTextField("focus is here"), BorderLayout.NORTH );
              getContentPane().add( new JButton("Button1") );
              getContentPane().add( new JScrollPane( new JTextArea(5, 30) ), BorderLayout.SOUTH );
         public static void main(String[] args)
              Test1 frame = new Test1();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
    }

  • 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();
    }

  • Open JTabbedPane with focus in tab

    I have a swing standalone app where general navigation is managed with something like this:
       private void addNewComponent(JComponent component) {
          JComponent panel = main.getDesktopComponent();
          main.setMainTittle(GlobalOptions.getTittle());
          panel.removeAll();
          panel.add(component, BorderLayout.CENTER);
          component.requestFocus();
          panel.validate();
          panel.repaint();
       } //EOF addNewComponentOne of this changed central panel's components is a JTabbedPane
    This pane has 3 tabs, each with full tree of containers and components.
    The problem is that when central app panel shows the JTabbedPane, the only way to focus in a component is by mouse click, after that i can use tab key to switch between components, including tabs from pane.
    I cant find a way to force focus so mouse click is not necesary.
    The component parameter in previous code has been a container in any part of app code I've seen it, so far, somewhere in each of this containers is a back button to mantain consistent the navigation. But I need to keep anytime the tab key navigation.
    Also while tab key is not working sometimes hot keys neither work, so fast keyboard navigation crashes completely.
    Is there a way I can fix this? tabs in JTabbedPane cant be selected as components, requestFocus in other components doesnt work, searching in the net shows posts with similar problems but says that it's a bug and need to change to jdk 1.5, I prefer to keep 1.4.2 version at least for a while since app is spreaded to many people and i dont control that.
    Thanks in advance for the help.

    You need to look into the new focus system. Focus always defaults the root of the default FocusTraversalPolicy. You need to define a policy. Then when the window opens focus will default to the tab if defined correctly.

  • How can I draw the tab of JTabbedPane as an image?(urgent)

    I would like to draw a JTabbedPane with a tab as an image or set the its size like I want.
    Any help is appreciated.

    Hi,
    you can set size the tabs by using the tabInsets key.
    Notice also the textIconGap key.
    UIDefaults ui = UIManager.getDefaults();
    ui.put("TabbedPane.tabInsets", new javax.swing.plaf.InsetsUIResource(10,10,10,10));
    "TabbedPane.textIconGap" int
    These are the keys and values connected with TabbedPane.
    If you need further customization of the tabbed pane I would suggest building your own.
    "TabbedPane.selected", Color
    "TabbedPane.tabRunOverlay" int
    "TabbedPane.tabAreaInsets" InsetsUIResource
    "TabbedPane.shadow" ColorUIResource
    "TabbedPane.selectedTabPadInsets" InsetsUIResource
    "TabbedPane.highlight" ColorUIResource
    "TabbedPane.lightHighlight" ColorUIResource
    "TabbedPane.font" FontUIResource
    "TabbedPane.foreground" ColorUIResource
    "TabbedPane.background" ColorUIResource
    "TabbedPane.focus" ColorUIResource
    "TabbedPane.darkshadow" ColorUIResource
    "TabbedPane.contentBorderInsets" InsetsUIResource
    -Michael

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

  • Lose focus when tabbing out of autoSubmit text box in IE

    Hey,
    Using JDEV 11.1.1.4 I have a problem with tabbing from one textbox to another textbox in IE. Both text boxes have autoSubmit=true and to reproduce the problem it's like so:
    I type a value or edit the existing one into text box 1 and press Tab. The submit is done and focus is given to the second text box but only momentarily before it loses focus. The focus then is given to the window it would appear, because if I press Tab again it begins from the top of the page. This is only happening in IE (v8 is all I have tried so far). This ONLY happens when the value of the second box is null. If it has a value all works fine.
    I tried implementing various solutions including using the ExtendedRenderKitService to write javascript to the client from the bean to set focus on the text box after the partial render. The javascript is called and focus is set but then something else calls blur on it afterwards. I have verified this by putting a blur event listener on it and it gets called after I set focus on it from my own javascript!
    Has anyone experienced something similar? Just to note: It only happens in IE, and it only happens when the second text box is empty.
    Thanks,
    Ross

    Hey John,
    In reply to your message
    1). Tried on 11.1.1.6 to see if the issue is still there?Not really an option to try and upgrade and test if it works there.
    2). Made a simple test case removing as many variables as possible (e.g. do a simple screen with no DB interaction and only two fields) to see if it reproduces or it's something with your screen?Tried this an it works fine which means it is something unique to my code.
    3). Filed an SR at https://support.oracle.com with your test case
    As above it looks like it's not a problem with ADF so I will keep looking at it.

  • Setting focus in a PDF form

    Hi,
    I'm trying to move a cursor to a particular field based on certain conditions using JavaScript. The method I am using is xfa.host.setFocus("fldTest"); in the initialize event. For some reason the focus isn't getting set to fldTest, but when I first hit tab it goes into the first field that is in the tab order. Is there any way around this?
    Thanks,
    Chad

    You might want to check the reference path of the field that you want to set focus on.
    Ex: xfa.host.setFocus("form1.page1.subform1.TextField1");

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

  • Setting Focus to datagrid next Item renderer column

    Hi
    I am having spark datagrid with 7 colum, I am facing problem to set focus for item renderer element.
    Below is my datagrid, when user enter some text in text input and press TAB key, I want trade button to be in focus. and from trade column Tab key press I want delete button to be in focus.
    I tried giving
    tabEnabled="true" tabChildren="false" tabFocusEnabled="true" editable="true" hasFocusableChildren="true"
    for datagrid.
    Also i tried giving selectedCell
    var _focusedCell:Object = new Object();
                                                                _focusedCell.rowIndex = dgTermDepo.selectedIndex;
                                                                _focusedCell.columnIndex = 5;
                                                                dg.selectedCell = _focusedCell as CellPosition;
    but nothing is working, I know I am missing some logic or property, Please suggest me on this
    Thanks
    Sonu

    You need to dig down into the event object and look at the
    listData.
    public function clickMe(e : MouseEvent ):void {
    var rowIndex : int = e.currentTarget.listData.rowIndex
    var colIndex : int = e.currentTarget.listData.columnIndex
    if the listData object is null when you try this you may need
    to add the following methods as overrides to the renderer or create
    a base renderer and extend all your renderers from the base
    renderer so that you always override these methods.
    [Bindable("dataChange")]
    private var _listData : BaseListData;
    override public function get listData() : BaseListData {
    return _listData;
    override public function set listData( value : BaseListData )
    : void {
    _listData = value;
    }

  • Avoid body focus during tabbing

    After opening Firefox and placing cursor in address bar, try pressing tab button. Now focus will set on each element like Address bar, Search window, body of the opened webpage. This is where im facing the problem. I don't want firefox to set focus on the body element while pressing tab i.e whole body gets focused. And also that does not make any sense , why the focus is setting to body of the page because we cant do any stuff by setting focus to the body of the element. I tried with other browsers , which works perfectly fine. But i like to stick to Firefox, the browser which i love the most. Being a developer i tried with lots of stuffs, but couldn't make out solution for it.Can u please provide the solution for it ? or the script which will avoid the focus of body element ?

    If you keep pressing the Tab key then the other focusable elements on the web page get focus, so the cycle doesn't end with focusing the body element.

  • Each tab of JTabbedPane has different border color

    Is it possible for the content area of each tab in JTabbedPane to have a different border color? Selecting Tab1 highlights content area of the tabbed pane in yellow, selecting tab2 highlights it in red, etc...
    Thanks

    Thanks for the quick response splungebob. How would I get a reference to the Jpanel of a specific tab? In my case each tab will have a toolbar, so I tried setting the toolbar border yellow, but I still have the default jtabbedpane border color surrounding my yellow bordered toolbar. I would prefer to set the color on the jtabbedpane, so that way the Tab itself does not also have the border going underneath it. For instance, I don't want the border to continue underneath the "my tab" tab, as illustrated below:
       | my tab |
    |                                                  |
    |                                                  |
    ----------------------------------------------------Edited by: 816886 on Nov 30, 2010 7:53 AM

Maybe you are looking for

  • Connecting a Buffalo Linkstation Live to an AE network

    I just bought a Buffalo Linkstation Live HS500GL on closeout at Circuit city. I have it hooked up to my AE via ethernet, but I can't "see" it on the network. The supplied software, the NAS Navigator seems to find it, and shows the IP address, and all

  • Clound control 12c : database not found

    Hi oracle aces, I've installed could control in a redhat host (OMS and AGENT, both installed and running ok) the host contains two databases : the repository database for EM and the database I want to monitor (same ORACLE_HOME, both are configured in

  • Outlook 2007 Calendar Reminders Still Making Sound on IPhone

    I recently got an Iphone, and synch to my Outlook 2007 calendar. Although I set the Calendar Reminder (can't remember exactly what it's called) in the iphone 'Settings' to 'Off', my iphone still makes a sound when a reminder is generated by Outlook.

  • QuickTime flickering during Video Tutorials?

    When I am watching the Video Tutorials for any of Apple products my QT flickers dark and light, not to the point where I can't see the video, but to the point where it is annoying. Anyone else having this problem? This is on a 4 day old new MacBook.

  • Oracle 11g Fusion Middleware Control, CGICMD.DAT

    Finally, I have Weblogic and Oracle 11g Forms and Reports up and running.  Now, I would like to create a Mapping Key in the CGICMD.DAT file, so that all the login information will not show up in the URL when I run a report.  Can someone please tell m