JTabbedPane - focus on a new tab

I'm making a GUI that creates new tabs containing components selected by the user.
graphTabs.add("Data Chart", chart); Can anyone tell me how to make the program focus on this new tab? As it is, the previous tab is still at the front of the screen when the new tab is created.
Thanks
Lev

I've solved it now, I looked at the api but didnt know what to look for, you can do it with indexOfTab(getTabCount - 1).

Similar Messages

  • How do I get FF to focus on a new tab? I right-click and choose "Open in New Tab" and the Tab appears in the Tab bar but I cannot access or see the new page.

    I open FF ver.10. My Home page is Google Search. I use a Bookmark and open, say, Hulu.com. I select a link by right-clicking and choose "Open in New Tab" The little tab in the tab bar opens but I am still viewing the Hulu.com main page and cannot view the new tab.
    This happens even if I use middle-click to open a new tab. It happens with all links on any website I visit.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Opening a site from Bookmark Toolbar in a new tab steals focus eventhough all new tab behaviors are set to not steal focus.

    When I open a site from my [Bookmarks Toolbar] (feeds) in a new tab, the site is opened in a new tab and FF switches to it.
    I have already unchecked [Options]~>[Tabs]~>["When I open a link in a new tab, switch to it immediately."].
    I have also set [browser.tabs.loadBookmarksInBackground] to true.
    The bookmarks/feeds open new tabs in the background properly, but opening the site from the bookmark toolbar does not.
    Is this a bug? Is there a setting I am missing to fix this?
    Example of what is happening now:
    {Left Click} [Bookmarks Toolbar]
    {Mouseover} [xkcd.com] (expand feed folder)
    {Middle Click} [Open "xkcd.com"] (at top of list of feed links)
    xkcd.com site now opens in a new tab and FF switches to it.
    I want the site to open the in a new tab in the background like the feed links already do with my settings.

    Works for me if I middle-click a bookmark on the Bookmarks Toolbar and browser.tabs.loadBookmarksInBackground is set to true.
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance/Themes).
    *Don't click the Reset button on the Safe mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • Focus-requests when switching tabs in JTabbedPane

    I have a tabbed pane with a JTextArea in each tab. I would like to switch focus to the corresponding area each time I select a tab or create a new one. A ChangeListener can detect tab selections and call requestFocusInWindow() on the newly chosen tab's text area.
    For some reason, the focus only switches sporadically. Sometimes the caret appears to stay, sometimes it only blinks once, and sometimes it never appears. My friend's workaround is to call requestFocusInWindow() again after the setSelectedIndex() calls, along with a Thread.sleep() delay between them. Oddly, in my test application the delay and extra focus-request call are only necessary when creating tabs automatically, rather than through a button or shortcut key.
    Does the problem lie in separate thread access on the same objects? I tried using "synchronized" to no avail, but EventQueue.invokeLater() on the focus request worked. Unfortunately, neither the delay nor invokeLater worked in all situations in my real-world application. Might this be a Swing bug, or have I missed something?
    Feel free to tinker with my test application:
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    /**Creates a tabbed pane with scrollable text areas in each tab.
    * Each time a tab is created or selected, the focus should switch to the
    * text area so that the cursor appears and the user can immediately type
    * in the area.
    public class FocusTest2 extends JFrame {
         private static JTabbedPane tabbedPane = null;
         private static JTextArea[] textAreas = new JTextArea[100];
         private static int textAreasIndex = 0;
         private static JButton newTabButton = null;
         /**Creates a FocusTest2 object and automatically creates several
          * tabs to demonstrate the focus switching.  A delay between creating
          * the new tab and switching focus to it is apparently necessary to
          * successfully switch the focus.  This delay does not seem to be
          * necessary when the user fires an action to create new tabs, though.
          * @param args
         public static void main(String[] args) {
              FocusTest2 focusTest = new FocusTest2();
              focusTest.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              focusTest.show();
              //Opens several tabs.
              for (int i = 0; i < 4; i++) {
                   try {
                        //adding the tab should automatically invoke setFocus()
                        //through the tabbed pane's ChangeListener, but for some
                        //reason the focus often doesn't switch or at least doesn't
                        //remain in the text area.  The workaround is to pause
                        //for a moment, then call setFocus() directly
                        addTabbedPaneTab();
                        //without this delay, the focus only switches sporadically to
                        //the text area
                        Thread.sleep(100);
                        setFocus();
                        //extra delay simply for the user to view the tab additions
                        Thread.sleep(1900);
                   } catch (InterruptedException e) {
         /**Adds a new tab, titling it according to the index of its text area.
          * Using "synchronized" here doesn't seem to solve the focus problem.
         public static void addTabbedPaneTab() {
              if (textAreasIndex < textAreas.length) { //ensure that array has room
                   textAreas[textAreasIndex] = new JTextArea();
                   //title text area with index number
                   tabbedPane.addTab(
                        textAreasIndex + "",
                        new JScrollPane(textAreas[textAreasIndex]));
                   tabbedPane.setSelectedIndex(textAreasIndex++);
         /**Constructs the tabbed pane interface.
         public FocusTest2() {
              setSize(300, 300);
              tabbedPane = new JTabbedPane();
              //Action to create new tabs
              Action newTabAction = new AbstractAction("New") {
                   public void actionPerformed(ActionEvent evt) {
                        addTabbedPaneTab();
              //in my real-world application, adding new tabs via a button successfully
              //shifted the focus, but doing so via the shortcut key did not;
              //both techniques work here, though
              newTabAction.putValue(
                   Action.ACCELERATOR_KEY,
                   KeyStroke.getKeyStroke("alt T"));
              newTabAction.putValue(Action.SHORT_DESCRIPTION, "New");
              newTabAction.putValue(Action.MNEMONIC_KEY, new Integer('T'));
              newTabButton = new JButton(newTabAction);
              Container container = getContentPane();
              container.add(tabbedPane, BorderLayout.CENTER);
              container.add(newTabButton, BorderLayout.SOUTH);
              //switch focus to the newly selected tab, including newly created ones
              tabbedPane.addChangeListener(new ChangeListener() {
                   public void stateChanged(ChangeEvent evt) {
                        //note that no delay is necessary for some reason
                        setFocus();
         /**Sets the focus onto the selected tab's text area.  The cursor should
          * blink so that the user can start typing immediately.  In tests without
          * the delay during the automatic tab creation in main(), the cursor
          * sometimes only blinked once in the text area.
         public static void setFocus() {
              if (tabbedPane == null) //make sure that the tabbed Pane is valid
                   return;
              int i = tabbedPane.getSelectedIndex();
              if (i < 0) //i returns -1 if nothing selected
                   return;
              int index = Integer.parseInt(tabbedPane.getTitleAt(i));
              textAreas[index].requestFocusInWindow();
    }

    Did you ever get everything figured out with this? I have a similar problem ... which I have working, but it seems like I had to use a bunch of hacks.
    I think the problem with the mouse clicks is because each event when you click the moues (mousePressed, mouseReleased, mouseClicked) causes the tab to switch, and also these methods are called twice for some reason - for a total of 8 events giving the tab the focus instead of your textarea.
    This works, but seems aweful hacky:
         class TabMouseListener extends MouseAdapter
              private boolean switched = false;
              public void mousePressed( MouseEvent e ) { checkPop( e ); }
              //public void mouseReleased( MouseEvent e ) { checkPop( e ); }
              //public void mouseClicked( MouseEvent e ) { checkPop( e ); }
              public void checkPop( MouseEvent e )
                   if( e.isPopupTrigger() )
                        mousex = e.getX();
                        mousey = e.getY();
                        int index = tabPane.indexAtLocation( mousex, mousey );
                        if( index == -1 ) return;
                        tabMenu.show( tabPane, mousex, mousey );
                   else {
                        if( !switched )
                             switched = true;
                             e.consume();
                             int index = tabPane.indexAtLocation( e.getX(), e.getY() );
                             if( index != -1 )
                                  tabPane.setSelectedIndex( index );
                                  TabFramePanel panel = (TabFramePanel)tabPane.getComponentAt( index );
                                  if( panel != null ) panel.getInputComponent().requestFocus();
                        else {
                             switched = false;
                             TabFramePanel panel = (TabFramePanel)tabPane.getSelectedComponent();
                             if( panel != null ) panel.getInputComponent().requestFocus();
         }Do you know of a better way yet?
    Adam

  • How to put the focus on the address bar, when opening a new tab in Safari?

    Dear users, I'm using Safari 6.0.3 (8536.28.10) under OSX 10.8.3. Until recently, whenever I opened a new tab in Safari, the focus was always on the address bar, which was quite useful. However, since last week, maybe after an update (I don't know exactly), the focus of a new tab is always on the page, not the address bar. How can I go back to the previous configuration? I changed no options, it simply got sudeenly different, and it's quite annoying. Thank you for the help.

    From the Safari menu bar, select
    Safari ▹ Preferences ▹ Extensions
    If any extensions are installed, disable them and test.

  • Shift focus to new tab opened in backing bean

    Hi,
    I have a tree whose nodes are displayed as command links. On click of these links I have corresponding method action in my backing bean that generates the URL which is opened as a new tab on the browser. Below is what my method looks like in the backing bean.
    FacesContext ctx = FacesContext.getCurrentInstance();
    ExtendedRenderKitService erks =
    Service.getService(ctx.getRenderKit(), ExtendedRenderKitService.class);
    String url = "window.open('http://www.google.com', '_blank')";
    erks.addScript(FacesContext.getCurrentInstance(), url);
    We are using IE7 and the problem is that the browser opens a new tab but doesn't shift the focus to the new tab. I added a simple af:goLink on my page with the targetFrame as"_blank" and it works fine. But its the script that I'm calling from my backing bean doesn't behave in the same way. We cannot ask the users to change their browser settings.
    Jdev 11.1.1.5.0.
    Thanks

    Thanks Frank,
    Since I'm generating this URL from the backing bean I did change the script in my backing bean to
    ExtendedRenderKitService erks = Service.getService(ctx.getRenderKit(), ExtendedRenderKitService.class);
    erks.addScript(FacesContext.getCurrentInstance(), "window.open('http://www.google.com', '_blank').focus();");
    But that also didn't move the focus to the new tab. When I embed the same string in the javascript on the page(jspx) it works fine.

  • How to disable "Double Click on Tab Bar to Open New Tab" feature?

    Since I upgraded to FF3 I've noticed this very annoying feature with tabs. If you double-click the 2-3 pixel wide bar just beneath tabs, it opens a new empty tab and sets the focus to that new tab (Which means I then have to go close that tab before going back to the tab I originally wanted). I happen to do this a lot by mistake (I go to click on a tab, but haven't clicked high enough, and of course, it doesn't change to the tab, so I unconsciously click again, which activates a new tab). I never open new empty tabs (alt-enter + middle click), and I have tabs to load in the background (i.e. to not *steal* the focus), so everything about this feature serves as an annoyance to me. Is there anyway to disable this "feature" (Either by disabling it, or making the width of the bar 0. I don't care either way)?
    == This happened ==
    Every time Firefox opened
    == I upgraded to FF3

    You can hold down the mouse button on a scroll button a bit longer to initiate scrolling multiple tabs.<br />
    Otherwise you need to wait longer between the clicks on the scroll button.<br />
    If you click twice on a tab bar scroll button too fast then you perform a 'page up' or 'page down' and the tabs scroll a tab bar width like you noticed.
    I'm not sure what you mean with new feature because this is the behavior in Firefox 3.6.x as well.

  • Hi. Whenever I open a new tab, Firefox jumps to it even though I've unticked that in the Options menu. Any ideas?

    no further details.

    Tab Mix Plus also has an option to immediately switch/focus on a new tab when opening.
    Your version of the following plugin has known security issues and should be updated.
    * Adobe Shockwave for Director Netscape plug-in, version 11.0
    #'''Check your plugin versions''': http://www.mozilla.com/en-US/plugincheck/
    #*'''Note: plugin check page does not have information on all plugin versions'''
    #'''Update Shockwave for Director'''
    #*NOTE: this is not the same as Shockwave Flash; this installs the Shockwave Player.
    #*Use Firefox to download and SAVE the installer to your hard drive from the link in the article below (Desktop is a good place so you can find it).
    #*When the download is complete, exit Firefox (File > Exit)
    #*locate and double-click in the installer you just downloaded, let the install complete.
    #*Restart Firefox and check your plugins again.
    #*'''<u>Download link and more information</u>''': http://support.mozilla.com/en-US/kb/Using+the+Shockwave+plugin+with+Firefox

  • "Select new tabs as they are created"

    I don't want new tabs to be "focused" on when I create them, meaning, when I make a new tab, I do not want Safari to then "focus" on that new tab, I would rather I stay at the page I am currently on until I want to go to that tab. I thought that unchecking the preference "Select new tabs as they are created" would do that, but it doesn't.
    Could someone inform me what that preference actually does?
    Thank you!!

    That preference works for me. How about unchecking the tabbed browsing setting entirely, then close Safari, open it again, and change your setting again. Maybe that is what is needed.

  • How to make Firefox stay on current tab, while opening new link in new tab.

    I want Firefox to stay in the current tab window after clicking a link. I want the link to open in a new tab window, but not switch to it automatically.
    In a nutshell, I want to be able to click on a link and have it act the same way it does when I right click and select "open link in new tab".

    { Ctrl + click } or Middle-click on hyperlinks to open that link in a new Tab.
    As far as whether or not the new Tab grabs focus, that will depend on how the webpage wants that link to be opened. Some JavaScript links will just open the tab and focus on that new Tab. You would need a tab-related add-on to change that, in some cases.

  • How to pause stage/swf with audio when a new tab is opened/ out of focus in browser

    I have created a container in Flash Professional CS5 for my project’s CBT.  I’ve been able to script many of the features we require using AS3, but there are a couple of things I’m still trying to work out.
    I would like the swf presently playing in one tab to pause and go silent when another swf is opened in a new tab (the sound is inside this externally loaded swf which is loaded inside a movie clip from buttons nested a movie clip down).  I’ve tried :
    var originalFrameRate:uint = stage.frameRate;
    var standbyFrameRate:uint = 0;
    addEventListener(Event.ACTIVATE, onActivate);
    addEventListener(Event.DEACTIVATE, onDeactivate);
    function onActivate(e:Event):void
           stage.frameRate = originalFrameRate;
           trace("in focus");
    function onDeactivate(e:Event):void
           stage.frameRate = standbyFrameRate;
           SoundMixer.stopAll();
           trace("out of focus");
    And
          I’ve looked into the HTML tag “has Priority”
    and coded buttons to:
    function fl_ClickToGoToWebPage(event:MouseEvent):void
           navigateToURL(new URLRequest("http://www.ansaldo-sts.com/AnsaldoSTS/EN/index.sdo"), "_blank");
           MovieClip(this.stage).stop();
    With variations of:
    MovieClip(this.parent.parent)stop();
    MovieClip(this.parent.parent.parent.parent)stop(); because the button is 3 movie clips deep.
    MovieClip(this.root)stop();      MovieClip(root)stop();MovieClip(this.currentTarget.root)stop();
    Could someone please provide me with the code?
    This function is present when I publish the CBT with Captivate, so obviously there must be code available. You can set the Captivate button to open url in new window and pause movie.
    Is there something I can add to the html file that is similar to the “has Priority” for mobile devices or is there javascript that can be added to the flash itself?

    You would send a command to Flash from JavaScript when window.onblur event occurs.

  • My default search engine is Google and I deleted Bing. Whenever I open a new tab, Bing is displayed and it takes the focus so if I am trying to type a URL in the new tab, it is entered in the damn bing search box. HOW DO I GET RID OF THAT ACCURSED BING?

    My default search engine is Google and I deleted Bing from the Search Providers. Facebook is set as my home page. Whenever I open a new tab, a Bing search box is displayed on the page and it takes the focus so when I am trying to type a URL in the new tab, it is entered in the damn bing search box. HOW DO I GET RID OF THAT ACCURSED BING

    Swarnava, thank you very much! that did it and I am Bing-less . . . OH HAPPY DAY!! WOOHOO!!!! thank you, thank you, thank you!

  • How can I make firefox give the focus (the cursor) to the address bar when I open a new window - as it does when I open a new tab (to about:blank)?

    When I open a new tab using CTRL-T, the address/awesome bar has the focus.
    When I open a new window using CTRL-N, it does not.
    Can the behaviours be made consistent via setting a configuration option or key?
    Thanks in advance for any help!

    Hello wodow, please check it in [https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode#firefox:linux:fx27 safe mode], do you have the same behaviour ? DO NOT reset, select "Start in Safe Mode".
    thank you

  • Why does Firefox switch focus to an immediately adjacent tab (in a series of tabs) on middle-clicking a link instead of staying on the same tab? (with setting of NOT switching to new tab).

    I have usually 4 tabs open by default. If, for example, I'm in the first tab and middle-click a link to open a new tab, the tab opens but firefox focuses on the tab immediately adjacent to the tab I'm on (in this case, from tab 1 to tab 2 instead of staying on tab 1 whilst tab 5 is loading). The pattern repeats if I'm on tab x and open a new tab from tab x, but focus shifts to tab (x+1) instead of staying on tab x.
    It happens more often than not, i.e. it sometimes stops but usually happens.
    I have this setup for a year now and this is the first time this is happening. I believe since this latest update of 3.6.13.

    This issue can be caused by an extension or plugin that isn't working properly.
    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")

  • Add button to JTabbedPane to add new tab

    Does anyone know how to add a JButton to a JTabbed pane (in the tab bar) so that it is always at the end of all the tabs and when it is clicked it will add a new tab into the tabbed pane.
    The functionallity I am looking for is the same as that provided by the button in the tab bar for Firefox and Internet Explorer.

    Along the line of what TBM was saying:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class NewTabDemo implements Runnable
      JTabbedPane tabs;
      ChangeListener listener;
      int numTabs;
      public static void main(String[] args)
        SwingUtilities.invokeLater(new NewTabDemo());
      public void run()
        listener = new ChangeListener()
          public void stateChanged(ChangeEvent e)
            addNewTab();
        tabs = new JTabbedPane();
        tabs.add(new JPanel(), "Tab " + String.valueOf(numTabs), numTabs++);
        tabs.add(new JPanel(), "+", numTabs++);
        tabs.addChangeListener(listener);
        JFrame frame = new JFrame(this.getClass().getName());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(tabs, BorderLayout.CENTER);
        frame.pack();
        frame.setSize(new Dimension(400,200));
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      private void addNewTab()
        int index = numTabs-1;
        if (tabs.getSelectedIndex() == index)
          tabs.add(new JPanel(), "Tab " + String.valueOf(index), index);
          tabs.removeChangeListener(listener);
          tabs.setSelectedIndex(index);
          tabs.addChangeListener(listener);
          numTabs++;
    }

Maybe you are looking for

  • Error While runing a report

    Hello, I am getting following error message when i run the report "Source selection for XCCALDATE__XCFISCLYR is incompatible for target selection " Thanks.

  • Why do some YouTube videos stop playing after a short time?

    Since sometime in October, 2013, I have noticed that more and more YouTube videos stop playing within a minute of starting. Most that stop do so in 15 or 16 seconds. The playing stops because the download stops. I watch this on a network activity mon

  • Strange problem with mac mini hdmi, denon avr 3310 and itunes

    Hello, I just bought the new mac mini with HDMI. It is connected via HDMI to my receiver Denon AVR 3310. The receiver shows that it has "multi channel in" on the display. I made all the configurations so that i can watch dvd an the mac mini. When i p

  • ADF Faces: Making a selectOneChoice in java code?

    I need to make a selectOneChoice to reuse in my pages (country selection) but can't seem to find how to do it on the web? here is what i've attempted with the error output... -------------------- the java code: public void contextInitialized(ServletC

  • Sending output to 2 pipelines in shell script?

    I have a large file to process using grep, however the same output of grep will be used by 2 different programs. Processing the large input file twice will be a waste of time. Is there a way to duplicate the output data and send it to 2 separate pipe