1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Focus on the last active tab when closing current one?

Discussion in 'Java' started by Annorax, Mar 1, 2008.

  1. Annorax

    Annorax New Member

    Joined:
    Nov 12, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    QA Engineer
    Location:
    MA, USA
    Hi everyone,

    I have a JTabbedPane and I am trying to figure out how to code it so that when closing the current tab, the last active tab is focused. I have some methods as below but they do not work as when closing, the stateChange method is called. Does anyone know how to code this and have it be n levels deep, not just one?
    Code:
    	    frame.tabbedPane.addChangeListener(new ChangeListener() {
    	        public void stateChanged(ChangeEvent e) {
    	        	previousTab = currentTab;	    
    	        	currentTab = frame.tabbedPane.getSelectedIndex();
    	        	System.out.println("old: " + previousTab);
    	        	System.out.println("current: " + currentTab);
    	        }    
    	    });
    
    public static void closeTab(JFrame frame1) {
            Component c = frame1.tabbedPane.getSelectedComponent();
            if( c != null ){
            		frame1.tabbedPane.remove(c);
    	        	System.out.println("Setting tab: " + previousTab);
    	        	frame.tabbedPane.setSelectedIndex(previousTab);
    	        	currentTab = frame.tabbedPane.getSelectedIndex();
            }
    }
     
    Last edited by a moderator: Mar 4, 2008

Share This Page