JideTabbedPane - detecting close button click

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

JideTabbedPane - detecting close button click

Postby billesbach » Wed Aug 15, 2007 10:32 am

How do you recommend detecting when the user closes a tab in a JideTabbedPane? How can I prevent the closing?

Background:
I'd like to be able to intercept the closing of a tab in a JideTabbedPane and optionally prevent the closing. This would be useful in the case that the enclosed panel requires saving changes. I can display a Save, Don't Save, Cancel dialog.
billesbach
 
Posts: 2
Joined: Wed Aug 15, 2007 10:23 am

Postby JIDE Support » Wed Aug 15, 2007 10:35 am

The default close action simply closes the selected tab. But you can set your own calling JideTabbedPane#setCloseAction(). Then you can do whatever in your own action code.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 36468
Joined: Sun Sep 14, 2003 10:49 am

Re: JideTabbedPane - detecting close button click

Postby icemedia » Fri Jan 07, 2011 8:51 pm

hi,
I can do things in the close action but, after that, how can I close the tab?
Code: Select all
 @Override
                public void actionPerformed(ActionEvent e) {
                    Component b=(Component )e.getSource();                   
                    b.dispose();
                    b=null;
                    // now the component has disposed but tab is still there...
                }
icemedia
 
Posts: 2
Joined: Fri Jan 07, 2011 8:44 pm

Re: JideTabbedPane - detecting close button click

Postby JIDE Support » Fri Jan 07, 2011 9:45 pm

You use delegation. You can get the default close action using getCloseAction() first, pass it to your action and call oldAction.actionPerformed() in your action's actionPerformed.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 36468
Joined: Sun Sep 14, 2003 10:49 am

Re: JideTabbedPane - detecting close button click

Postby icemedia » Fri Jan 07, 2011 11:41 pm

thank you for your quik reply, my code is as below:
it seems that I can't get old action (tab.getCloseAction() returns null)

Code: Select all
 tab.setCloseAction(new MyCloseAction(tab.getCloseAction()));
...
class MyCloseAction implements Action{
    Action oldAction=null;
    public MyCloseAction(Action oldAction){
        this.oldAction=oldAction;
    }
    @Override
    public Object getValue(String key) {
        return null;
    }

    @Override
    public void putValue(String key, Object value) {       
    }

    @Override
    public void setEnabled(boolean b) {       
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    @Override
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        oldAction.actionPerformed(e);
        //exception comes out here says oldAction is null...
    }

}

icemedia
 
Posts: 2
Joined: Fri Jan 07, 2011 8:44 pm

Re: JideTabbedPane - detecting close button click

Postby JIDE Support » Sat Jan 08, 2011 12:10 am

Never mind. We have a CloseTabAction defined but it is not set to JideTabbedPane's closeAction. It is defined in ActionMap with name "closeTabAction". You can look it up in the ActionMap. Unfortunately in the CloseTabAction, we have this statement.

Code: Select all
if (pane.getCloseAction() != null) {
      pane.getCloseAction().actionPerformed(e2);
}
else {
   // close the tab
}


So I don't think my original suggestion will work. You can look at the BasicJideTabbedPaneUI.java in the open source JCL to see the code. See if you can find a solution. Otherwise we will have to a veto solution here. We had it already in Docking Framework and DocumentPane where JideTabbedPane was used but not in JideTabbedPane itself.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 36468
Joined: Sun Sep 14, 2003 10:49 am

Re: JideTabbedPane - detecting close button click

Postby nick.denton » Mon Nov 21, 2011 9:37 am

Hi,

I have the same problem. I want to perform a task before closing the tab. So has someone found a solution for that?


Thanks,

Nick
nick.denton
 
Posts: 7
Joined: Wed Nov 16, 2011 6:02 pm

Re: JideTabbedPane - detecting close button click

Postby JIDE Support » Mon Nov 21, 2011 12:09 pm

Please try to override JideTabbedPane#removeTabAt(). Before calling super, please prompt a dialog according to the tab index. If it says OK, you could go ahead to call super. Otherwise, just simply return.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 36468
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: Google [Bot] and 5 guests

cron