JTabbedPane loosing focus when switching tabs

When there are tiered JTabbedPanes and focus in one of the children and the tabbed is switched focus will go to the first component in the frame.
Is there a work around to keep the focus at least on the jtabbedpane?
Is this a know bug? anyone heard of this before?
Googling: JTabbedPane focus didn't bring up anything helpful... is there something else I should be searching under?
Here is an example:
import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
public class TabPaneTest extends JFrame {
    public TabPaneTest() {
        JButton focusStealer = new JButton("Look at me!");
        focusStealer.addFocusListener(new FocusListener() {
            public void focusGained(FocusEvent e) {
                System.out.println("I TOOK FOCUS! W00t!");
            public void focusLost(FocusEvent e) {
                //To change body of implemented methods use File | Settings | File Templates.
        JTabbedPane tabbedPane = createTabbedPane(0);
        getContentPane().add(focusStealer, BorderLayout.NORTH);
        getContentPane().add(tabbedPane, BorderLayout.CENTER);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(300, 200);
        setLocation(400, 200);
        setVisible(true);
    private JTabbedPane createTabbedPane(int deep) {
        deep++;
        JTabbedPane tabs = new JTabbedPane();
        for (int i = 0; i < 4; i++) {
            if (deep < 4) {
                tabs.add(i + ":" + deep + " - Focus", createTabbedPane(deep));
            } else {
                tabs.add(i + ":" + deep + " - Focus", new JTextField());
        return tabs;
    public static void main(String[] args) {
        new TabPaneTest();
}

When there are tiered JTabbedPanes and focus in one of the children and the tabbed is switched focus will go to the first component in the frame.
Is there a work around to keep the focus at least on the jtabbedpane?
Is this a know bug? anyone heard of this before?
Googling: JTabbedPane focus didn't bring up anything helpful... is there something else I should be searching under?
Here is an example:
import javax.swing.*;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
public class TabPaneTest extends JFrame {
    public TabPaneTest() {
        JButton focusStealer = new JButton("Look at me!");
        focusStealer.addFocusListener(new FocusListener() {
            public void focusGained(FocusEvent e) {
                System.out.println("I TOOK FOCUS! W00t!");
            public void focusLost(FocusEvent e) {
                //To change body of implemented methods use File | Settings | File Templates.
        JTabbedPane tabbedPane = createTabbedPane(0);
        getContentPane().add(focusStealer, BorderLayout.NORTH);
        getContentPane().add(tabbedPane, BorderLayout.CENTER);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(300, 200);
        setLocation(400, 200);
        setVisible(true);
    private JTabbedPane createTabbedPane(int deep) {
        deep++;
        JTabbedPane tabs = new JTabbedPane();
        for (int i = 0; i < 4; i++) {
            if (deep < 4) {
                tabs.add(i + ":" + deep + " - Focus", createTabbedPane(deep));
            } else {
                tabs.add(i + ":" + deep + " - Focus", new JTextField());
        return tabs;
    public static void main(String[] args) {
        new TabPaneTest();
}

Similar Messages

  • After update to Firefox 25, tabs will "go back" 2 to 3 pages, when switching tabs or exiting full screen.

    It happens most frequently when exiting full screen from a video. i.e. youtube, dailymotion, nbc.com - any site with embedded video players.
    When exiting full screen, the page skips backwards 2 to 3 pages. And no, I'm not clicking related videos while in full screen the whole time - this is while initiating full screen and exiting full screen, all from the same video page.
    This happens less frequently when switching tabs - but if I switch to another tab, then back, the first tab will load the page I was on 2 pages ago.
    More info: When this happens, the "forward arrow" is greyed out and the page that that loads is on the "back arrow" list twice - further down the list where it should be, as well as at the very top of the list, as though I had clicked on a link to that page.
    This all started immediately upon restarting Firefox after updating to version 25 - no other changes have been made to my computer.

    Thanks for the canned responses, but you guys are way off.
    More information: It's related to HTML5 - whenever I fullscreen an HTML5 video, Firefox skips backwards to the most recent HTML5 video before that one, when exiting fullscreen. This last time, it skipped backwards past 4 pages that had no HTML5 content at all, to the one that did.

  • IPhone 4S Safari freezes when switching tabs

    Hi.
    Mobile Safari in my iPhone 4S freezes when switching tabs.  This does not happen every time Safari is running, but it happened one too many already.  Safari freezes even if I only have one tab and wanted to create a new one.  The app would usually freeze while doing the switch, tho it also froze just before the tabs switch.  Has anyone experienced the same?  Please help.  Thank you.   

    User troubleshooting after a reset is a restore. First from a backup and if that doesn't help, then as a new device. Remember a restore will delete data from the phone. Make sure you have everything backed up and synced to the computer before attempting the restore. If that does not help, make an appointment with the Apple Genius Bar to check for hardware faults.

  • Firefox unmaximizes itself when switching tabs in task bar

    When switching tabs using the windows taskbar during an extended online session spanning multiple tabs and windows, the window will unmaximize itself. Switching tabs using the physical tab works correctly. This only occurs with the "Show tabs preview in the Windows Taskbar" opton enabled. Closing all open firefox windows and restarting firefox is the only fix I have found.

    Hi achenbachs630420,
    This is expected behavior for the Windows 7 operating system. However when I have Firefox in fill screen mode for a window and hover over the taskbar the preview will show up and the full screen will remain, and I have the same feature selected, weird?
    '''Try Firefox Safe Mode''' to see if the problem goes away. [[Troubleshoot Firefox issues using Safe Mode|Firefox Safe Mode]] is a troubleshooting mode that turns off some settings, disables most add-ons (extensions and themes).
    If Firefox is open, you can restart in Firefox Safe Mode from the Help menu:
    *In Firefox 29.0 and above, click the menu button [[Image:New Fx Menu]], click Help [[Image:Help-29]] and select ''Restart with Add-ons Disabled''.
    *In previous Firefox versions, click on the Firefox button at the top left of the Firefox window and click on ''Help'' (or click on ''Help'' in the Menu bar, if you don't have a Firefox button) then click on ''Restart with Add-ons Disabled''.
    If Firefox is not running, you can start Firefox in Safe Mode as follows:
    * On Windows: Hold the '''Shift''' key when you open the Firefox desktop or Start menu shortcut.
    * On Mac: Hold the '''option''' key while starting Firefox.
    * On Linux: Quit Firefox, go to your Terminal and run ''firefox -safe-mode'' <br>(you may need to specify the Firefox installation path e.g. /usr/lib/firefox)
    When the Firefox Safe Mode window appears, select "Start in Safe Mode".<br>
    [[Image:Safe Mode Fx 15 - Win]]
    '''''If the issue is not present in Firefox Safe Mode''''', your problem is probably caused by an extension, and you need to figure out which one. Please follow the [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]] article to find the cause.
    ''To exit Firefox Safe Mode, just close Firefox and wait a few seconds before opening Firefox for normal use again.''
    When you figure out what's causing your issues, please let us know. It might help others with the same problem.

  • 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

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

  • ADF AutoSubmit True column Loosing Focus after hitting Tab

    Hi,
    I am on 11.1.2.2.0. I have implemented af:table component and inside table on few columns I have autoSubmit="true" immediate="true" . After entering values into those columns when I hit Tab (To go to next field in table) , it goes to next field and looses focus. Is there any work around or fix to overcome this issue ?
    Thanks and Regards,
    Jit

    Hi,
    Thanks for the links. My requirement is to set focus inside af:table. Inside table I have say 5 fields.
    3rd Field is LOV and 4th fields is Text. After entering LOV info in Field3 focus should go to field4(which is inputText).
    I tried
    Frank's Blog
    https://blogs.oracle.com/jdevotnharvest/entry/how_to_programmatically_set_focus
    AMIS Blog
    http://technology.amis.nl/2008/01/04/adf-11g-rich-faces-focus-on-field-after-button-press-or-ppr-including-javascript-in-ppr-response-and-clientlisteners-client-side-programming-in-adf-faces-rich-client-components-part-2/
    This works for ADF Form entry. When I tried implement this in table the field id(eg it4) is not picked.
    I found other blog for where it is mentioned field id dwill be different in case of Table.
    http://www.bartkummel.net/2009/11/oracle-adf-set-focus-to-input-field-in-data-table/#respond
    Do you have any idea how to get Table id or help in building this field id in Table ?
    Thanks and Regards,
    Jit

  • Call a Function when switching tabs in TabbedPanel

    I am using Allan Jardine's DataTables javascript library , along with the Spry TabbedPanel. I have one table in each of a number of Tabs. The table in the tab opened by default (or if I use ShowPanel()) is fine. However, if I switch tabs, the other tables, which were hiden when the page was opened,  are not correctly initialised, and don't display correctly. Doing anything that causes the displayed table to be redrawn results in the table displaying correctly, and from then on I can switch tabs and the tables are fine.
    DataTables has an API function fnDraw(), which will cause a specified table to be redrawn. Is it possible to cause TabbedPanel to call a user specified function when the tabs are swapped, so I can call fnDraw()? I think this woiuld solve my problem.
    Thanks
    Ron

    Thanks.
    But I found a simpler way. At the end of the jQuery(document).ready(function(), which initialises the datatables, I added
    var ret=TabbedPanels1.showPanel("expiredquotes");
    oTable2.fnDraw();
    var ret=TabbedPanels1.showPanel("confirmedquotes");
    oTable3.fnDraw();
    var ret=TabbedPanels1.showPanel("openquotes");
    Which opens each of the "other" tabs and redraws the respective DataTable while they are "visible". Then at the end I display the 'default' Tab. I only need to do this once, when the page is opened, after which the tables are correctly formatted.
    Regards
    Ron

  • Tabs and pages not drawn when switching tabs.

    When switching between tabs or opening new tabs, the tab and the page are not drawn. But if I scroll down the page is drawn.
    This doesn't happen always. It happens randomly.
    Here's some sample sample images:
    https://dl.dropboxusercontent.com/u/14279386/imghost/tabrender/1.png
    https://dl.dropboxusercontent.com/u/14279386/imghost/tabrender/2.png
    I've been having this problem since a few versions back.

    If it works in Safe Mode and in normal mode with all extensions (Firefox/Tools > Add-ons > Extensions) disabled then try to find which extension is causing it by enabling one extension at a time until the problem reappears.
    Close and restart Firefox after each change via "Firefox > Exit" (Windows: Firefox/File > Exit; Mac: Firefox > Quit Firefox; Linux: Firefox/File > Quit)
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    In Firefox Safe mode these changes are effective:
    *all extensions are disabled (about:addons)
    *default theme is used (no persona)
    *userChrome.css and userContent.css are ignored (chrome folder in profile folder)
    *default toolbar layout is used
    *JavaScript JIT compilers are disabled
    *hardware acceleration is disabled (Options > Advanced > General)
    *plugins are not affected
    *preferences are not affected

  • AIR app crashes when switching tabs

    Hi there:
    I posted in another forum about this, but it seems the issues
    aren't really related, so a recap:
    quote:
    Originally posted by:
    patrickcheatham
    I am trying to run an AIR app which _crashes_ as soon as it
    needs to access a file or files on the hard drive (via an HTML
    component). Sometimes it just crashes, sometimes I get an error
    that the app can't find Adobe AIR. I have followed most or all of
    the suggestions in
    this
    thread.
    Attached code is a crash report.
    Thanks!
    The app can be found
    here
    The crash report can be found
    here
    The crash report has WebKit all over it; interstingly, when a
    user reported installing the Safari 4 Beta recently, all crashing
    stopped (that doesn't really make sense to me, but OK).
    quote:
    Originally posted by:
    patrickcheatham
    I have further input on this:
    1) The crash occurs when the user switches tabs;
    specifically, when the user switches from a tab which does _not_
    contain an HTML component, to one which _does_ contain an HTML
    component. Said HTML component looks for local content.
    2) The crash occurs when the app tries to phone home to
    Adobe; this phoning home appears to occur during item 1 above
    _and/or_ when the app is launched.
    Any help from above or insight appreciated.
    Thanks,
    Patrick

    Hi Mirela:
    It may be that the issue is a non-issue with AIR 1.5.1
    (versus v1.5), so we'll see. Frustrating, nonetheless, especially
    since it is a sporadic issue.
    You can follow other users' experiences in the forum at
    panosalado.com.
    Thanks for taking the time to download it and try it out --
    and for the feedback. Good to hear a positive! :)
    Cheers,
    Patrick

  • Refreshing when switching tabs

    Hi,
    I have created a webcenter site that has tabs used in iframes. What I would like to do is to refresh the bottom frame when a person switches tabs so the old data id removed. Does anyone know how to achieve this?
    Any help would be appreciated.
    -Joe

    What technology are you using? WebCenter Content with a Javascript frontend? Do you use JQuery or some other framework?
    Can you post the existing code that needs changing?

  • Loosing focus when quiting

    Hello,
    Can someone help me with the following problem? How can I force a JTextField to loose it's focus when I am quiting the program by clicking the x-icon?
    thanks
    Stef

    Hello.
    Add a mouse listener to your x-icon and in the mouse released method add this block
    component.requestFocus();
    which component can be any swing component like Jframe.

  • My windows keeps loosing focus when bluetooth goes active

    Hi, I have a problem with my bluetooth.
    When my bluetooth on my laptop goes active i.e. the "bluetooth B" in the bluetooth icon on the botton tray in Windows goes from white to green this problem accours. At that very moment, the current window I am working in goes inactive. If I am typing in a textbox for example and the bluetooth goes from "white to green", the textbox looses focus and I have to cklick it to resume my typing.
    How dow get rid of that problem and still have a reachable bluetooth device?
    Running on Windows XP Pro, laptop:
    Bluetooth Stack for Windows by Toshibe
    Version v4.42 (D)
    Bluetooth spec:
    Version 2.0, 1.2, 1.1
    Thanks!
    //Doman

    That could be the solution... but no luck..
    Now, I´m running with stack: v6.01.03(D)
    ...and the problem is still there.
    *More background:*
    I am using a SonyEricsson sync program, every morning I connect my mobile via this program. The program is set to autosync the first thing when it detecs the mobile via bluetooth. The laptop stays often in the it´s dock and when I leave it (with the mobile in my pocket) and come back, they find eachother again and the sync starts. This way I never need to start the sync by myself which I always forget otherwhise.
    The problem is that my computer sometimes checks if my mobile is still there (I suspect), and each time it starts to use the internal bluetooth device, the focus of current window I´m using is lost, this is of course very annoing when I´m writing something etc. This occurs regardless of the result of the search, ie regardless of it finds the phone or not.
    Is there any workaround without losing that my phone autoconnects with my computer and the sync starts?

  • JButton gains focus when Hitting tab key but hitting Enter has no effect.

    Hi,
    I have a program that has two buttons. When pressed, using the mouse, the buttons text appears in the middle of the screen. I have NOT alerted the focus subsystem. Thus when I press the tab key the buttons are highlighted in turn, to indicate that they currently have focus. However if I press enter the buttons actions (to update the middle of the screen with it's text) does not get activated.
    I am using 1.4.2 on a Windows machine.
    any help on this would be much appreciated !!
    The code is as follows:
    package com.logicacmg.skynet.tms.mmi.ui;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import java.awt.BorderLayout;
    import java.awt.Container;
    public class Test implements ActionListener
    JButton bTwo = new JButton("button 2");
    JButton b = new JButton("button 1");
    JLabel label = new JLabel(" ");
    /** Creates a new instance of Test */
    public Test()
    JFrame frame = new JFrame();
    //Create a panel to hold the MMI screens.
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    b.addActionListener(this);
    bTwo.addActionListener(this);
    mainPanel.add(b, BorderLayout.WEST);
    mainPanel.add(bTwo, BorderLayout.EAST);
    mainPanel.add(label, BorderLayout.CENTER);
    //add the main panel which contains the screens and the status bar
    //to this frame.
    Container contentPane = frame.getContentPane();
         contentPane.add(mainPanel, BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
    public static void main(String [] args)
    new Test();
    public void actionPerformed(ActionEvent e)
    JButton aButton = (JButton)e.getSource();
    if(aButton == b)
    label.setText("one");
    else if(aButton == bTwo)
    label.setText("Two");

    Which plaf are you using? Because when I switch to the windows plaf, the behavior is what you describe.
    Demo:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class X {
        public static void main(String[] args) {
            final JFrame f = new JFrame("button focus");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            ActionListener al = new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    System.out.println(evt.getActionCommand());
            Container cp = f.getContentPane();
            cp.setLayout(new FlowLayout());
            for(int i=0; i<3; ++i) {
                JButton btn = new JButton("Button " + i);
                btn.addActionListener(al);
                cp.add(btn);
                if (i == 1)
                    f.getRootPane().setDefaultButton(btn);
            final JCheckBox laf = new JCheckBox("platform plaf");
            laf.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent evt) {
                    String cls = laf.isSelected() ? UIManager.getSystemLookAndFeelClassName() :
                      UIManager.getCrossPlatformLookAndFeelClassName();
                    try {
                        UIManager.setLookAndFeel(cls);
                        SwingUtilities.updateComponentTreeUI(f);
                    } catch (Exception e) {
                        e.printStackTrace();
            cp.add(laf);
            f.pack();
            f.setVisible(true);
    }

  • Javascript bug when switching tabs

    Hello,
    I'm developing a simple web site with an image slideshow on the front page. The slideshow is powered by javascript and are using javascript's "setTimeout" function to toggle between images with a jQuery animation. However, when I switch to another tab and wait for a while, then switch back, it seems like all animations that should have been run in the background has been queued up and then runs simultaneously as soon as I switch back to the original tab. Basically it freaks out for a few seconds when all stacked up animations are run, and then it goes back to the normal behaviour.
    Is this a bug or a feature? And if it's a feature, how would you suggest that I code my javascript to avoid this problem?

    See Additional Notes -section of JQuery's animate-function documentation
    Because of the nature of requestAnimationFrame(), you should never queue animations using a setInterval or setTimeout loop. In order to preserve CPU resources, browsers that support requestAnimationFrame will not update animations when the window/tab is not displayed.
    '''If you continue to queue animations via setInterval or setTimeout while animation is paused, all of the queued animations will begin playing when the window/tab regains focus.'''
    To avoid this potential problem, use the callback of your last animation in the loop, or append a function to the elements .queue() to set the timeout to start the next animation.
    Source: http://api.jquery.com/animate/#notes-0

Maybe you are looking for

  • Why does the PC lockup when using a 6071E with an ASUS P5ND2-SLI motherboard?

    Please Help, Thanks, Brian Problem Summary: PC locks up to a point that will not allow keyboard control.  Sometimes the system reboots itself.  This code works on Win2000 systems and XP systems with a different motherboard.  I have the Hyperthreading

  • Event handling for Sharepoint datagrid

    I'm relatively new to SharePoint 2013.  For the past weeks I have been looking through on the web how to handle events in a sharepoint's datagrid view of a list. To be clear, I'm referring to that Excel style view that SharePoint allows you to edit q

  • Add webpart to Wiki page WPZ

    Hi, Is it possible to display a webpart in the hidden webpart zone of a wiki page? I have tried to add but it is not displaying, is this expected? I would want to display a webpart at the bottom of the page. Thanks, Sam

  • Automatically add Date events from Microsoft Word,MS Outlook to ical?

    Hi Was wondering if theres anyway(native or software) for outlook,word or ical to automatically scan and add date events from docs,mail to ical so that i can sync it to my iphone

  • Sync Problems...can anyone help??

    Hey all, I plugged in my Iphone 3g into Itunes to update some music and it will stay connected for about a minute or so and then it will all of a sudden get disconnected without me touching the usb cable. I updated my Iphone and Itunes so everything