Extending CCloseAction

I’m having problems when I try to extend CCloseAction, so that when a dock is closed some other things are trigged as well. I can create the extended class, but the extended code is not used, or the close button is not showed or is in the wrong place… Can you give me some pointers on how you would go about doing this in a DefaultSingleCDockable?

Can’t tell you why your code does not work, but here are some versions how I would solve this:


import javax.swing.JFrame;

import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CLocation;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.action.predefined.CCloseAction;
import bibliothek.gui.dock.common.event.CDockableAdapter;
import bibliothek.gui.dock.common.intern.CDockable;

public class Dock9 {
	public static void main( String[] args ){
		JFrame frame = new JFrame();
		
		CControl control = new CControl( frame );
		
		frame.add( control.getContentArea() );
		
		// 1. Subclass to catch the event at the source
		DefaultSingleCDockable dockable = new DefaultSingleCDockable( "a", "A" ){
			@Override
			public void setVisible( boolean visible ){
				System.out.println( "setVisible " + visible );
				super.setVisible( visible );
			}
		};
		
		// 2. Listener to be informed after the event is processed
		dockable.addCDockableStateListener( new CDockableAdapter(){
			@Override
			public void visibilityChanged( CDockable dockable ){
				System.out.println( "visibility changed" );
			}
		});
		
		// 3. Replace the close-action
		dockable.putAction( CDockable.ACTION_KEY_CLOSE, new Test( control ) );
		
		dockable.setLocation( CLocation.base().normal() );
		control.add( dockable );
		dockable.setCloseable( true );
		dockable.setVisible( true );
		
		frame.setBounds( 20, 20, 200, 500 );
		
		frame.setVisible( true );
	}
	
	private static class Test extends CCloseAction{
		public Test( CControl control ){
			super( control );
		}
		
		@Override
		public void close( CDockable dockable ){
			super.close( dockable );
			System.out.println( "close triggered" );
		}
	}
}

Wow, thanks for the super quick replay Beni. You helped alot :smiley: