Custom dockable title


I was wondering if you could help me with the following :

I have a couple of dockables for which I want to have a custom painter in the dockable’s title bar ( use some fancy gradients ).
However I am doing something wrong and some functionality is missing ( please read my comments in the following barebones working example )

Many thanks in advance for your time,

Kind regards,

import bibliothek.gui.dock.SplitDockStation;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CLocation;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.title.AbstractDockTitle;
import bibliothek.gui.dock.title.DockTitleFactory;
import bibliothek.gui.dock.title.DockTitleManager;
import bibliothek.gui.dock.title.DockTitleRequest;
import bibliothek.gui.dock.title.DockTitleVersion;
import bibliothek.gui.dock.util.Priority;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;

public class TEMP_FRAME extends JFrame
    public static void main(String[] args)
         TEMP_FRAME frame=new TEMP_FRAME();
         frame.setLayout(new BorderLayout());
         CControl control=new CControl(frame);
         DefaultSingleCDockable dock1=new DefaultSingleCDockable("Dock1");
         dock1.setTitleText("Dock 1");
         DefaultSingleCDockable dock2=new DefaultSingleCDockable("Dock2");
         dock2.setTitleText("Dock 2");

         /* If the following block of code - line XXX in particular - is commented out then :
         *  Clicking inside a dockable or inside a dockable's title bar , selects/focuses the dockable ( GOOD )
         *  If the following block of code - line XXX in particular - is not commented out then :
         *  Clicking inside a dockable or inside a dockable's title bar , has no effect ( NOT GOOD )
         *  But if you first click inside a dockable or inside the dockable's title bar and then :
         *    a) left-drag the horizontal "divider" line to resize the dockables 
         *    or
         *    b) resize the whole frame
         *  then it works.
         *  It seems like a repaint event is needed but does n't happen
            DockTitleManager titles=control.getController().getDockTitleManager();
            DockTitleVersion version=titles.getVersion(SplitDockStation.TITLE_ID,null);
            DockTitleFactory factory=new DockableTitleFactory();
            version.setFactory(factory,Priority.CLIENT);  // LINE XXX
         frame.setSize(new Dimension(500,500));
    static class DockableTitleFactory implements DockTitleFactory
        public void install( DockTitleRequest request ){}
        public void request( DockTitleRequest request )
            request.answer(new CustomTitle(request.getTarget(),request.getVersion()));
        public void uninstall( DockTitleRequest request ){}

        class CustomTitle extends AbstractDockTitle
            public CustomTitle( Dockable dockable, DockTitleVersion origin )

            protected void paintBackground( Graphics g, JComponent component )
                final boolean isCurrentlySelectedDockable=getDockable().getController().getFocusedDockable()==getDockable();
                final Color color=isCurrentlySelectedDockable?;

Instead of using getDockable().getController().getFocusedDockable()==getDockable(); you should better call this.isActive(). You can override setActive and fire a repaint event there. setActive is called everytime when the focused Dockable changes. You may want to have a look at BasicDockTitle and use it as an example of how a title can be implemented.

Yes! Thanks Beni!
Using isActive and overriding setActive(boolean isActive) as in :

public void setActive(boolean isActive){

did the trick!!

Many thanks!