Background of Panel holding Dockables

Hi Beni

Hoi can I set the background of the panel that holds the Dockables?

I tried to set the background of the WorkingArea but that did not help:


this.workingArea.getComponent().setOpaque(true);
this.workingArea.getComponent().setBackground(Color.RED);

In this image you can see what panel I mean:

Looking a bit in the code I created a custom theme and a custom EclipseTabPaneContent (I am using the EclipseTheme):

public MyTabPaneContent (MyTabPane pane) {
    super(pane);
    setOpaque(true);
    setBackground(Color.RED);
}

This worked and if I open a new Dockable the background of the panel that holds the Dockable is red. But this only works for closable Dockables. I initially have a non-closable Dockable in the frame and its background is not red.

I also added a debugging output to the paint method of MyTabPaneContent and it seems that this method is called all the time.

I’am not sure if setting the background on EclipseTabPaneContent is the correct way…

Do you have any suggestions?

Thank you in advance and greetings
Janneth

I just found out that it does not work for the first Dockable, independent if that Dockable is closable or not.

  1. Let me try to explain why you run into problems:

While the case with one tab and the case with many tabs look similar, they are handled differently by the framework:

Using the picture you uploaded: “Single Dockables” and “Multiple Dockables” are direct children of the SplitDockStation in the middle of the frame. The other two dockables are children of a StackDockStation, which in return is a child of the SplitDockStation.

The SplitDockStation uses for each child a “DockableDisplayer”, in this case an “EclipseDockableDisplayer”, to paint decorations like a border and a tab.

The StackDockStation, in the upper half of the image, uses a “StackDockComponent” (in this case a “EclipseTabPane”) to paint a line of tabs and for each child a displayer to paint the border.

Most likely you only replaced the “StackDockComponent”, but not the displayers.

  1. Now the solution I would use (requires the newest version of the framework): The EclipseTabPaneContent uses a TabPanePainter to paint foreground and background, it is possible to replace this painter. The TabPanePainter is created by a factory called “TabPainter”, this factory is stored in the properties.

First create a new TabPanePainter by subclassing LinePainter and overriding “paintBackground”

	private EclipseTabPane pane;
		
	public BackgroundPainter( EclipseTabPane pane ){
		super( pane );
		this.pane = pane;
	}
		
	@Override
	public void paintBackground( Graphics g ){
		g.setColor( Color.RED );
		JComponent parent = pane.getComponent();
		g.fillRect( 0, 0, parent.getWidth(), parent.getHeight() );
	}
}```

Then create a new factory. TabPainter has several methods, just use an existing factory to fill most of them:
```public class BackgroundTabPainter implements TabPainter{
	private TabPainter delegate = ArchGradientPainter.FACTORY;
			
	public TabPanePainter createDecorationPainter( EclipseTabPane pane ){
		return new BackgroundPainter( pane );
	}
	public InvisibleTab createInvisibleTab( InvisibleTabPane pane, Dockable dockable ){
		return delegate.createInvisibleTab( pane, dockable );
	}
	public TabComponent createTabComponent( EclipseTabPane pane, Dockable dockable ){
		return delegate.createTabComponent( pane, dockable );
	}
	public Border getFullBorder( BorderedComponent owner, DockController controller, Dockable dockable ){ 
		return delegate.getFullBorder( owner, controller, dockable );
	}
}```

And finally you have to plug-in the new factory:
```CControl control = ...
control.putProperty(EclipseTheme.TAB_PAINTER, new BackgroundTabPainter() );

[Edit: there will be gray lines between the Dockables. I think modifying the LookAndFeel itself, such that JPanels and JComponent are painted with some other background color, is the easiest solution to get rid of them]

Thank you very much, it worked perfectly!

I played a bit with the background colors and borders.

For those who are interested, here is an image that helps to find out which border is painted by which method:


In my application I am using a CWorkingArea to place my Dockables.

Now there is a small white border around the CWorkingArea that I cannot eliminate.

You can see this in the DockingFrames Paint Demo Application:

How can I eliminate this thin white border around the CWorkingArea?

When I switch to the Eclipse Theme in the Paint Demo, there is no such border.

What I do not understand is why this border is shown because actually I am using the EclipseTheme in my application.

control.setTheme(ThemeMap.KEY_ECLIPSE_THEME);
control.putProperty(EclipseTheme.TAB_PAINTER, new BackgroundTabPainter());

Do I need to create another custom painter for the CWorkingArea? If yes, which class do I need to override?

A Dockable can tell its parent panel to paint a border. DockStations do this, if they don’t have a child, thus the “empty” border appears.

There are at least two ways here:

  1. For all themes:
    a) Make a new class extending CSplitDockStation and override the methode “updateConfigurableHints” with:
    protected void updateConfigurableDisplayerHints(){
        DockableDisplayerHints hints = getConfigurableDisplayerHints();
        if( hints != null ){
            hints.setShowBorderHint( Boolean.FALSE);
        }
    }

b) Make a new class extending EfficientControlFactory and override the methode createSplitDockStation, return your new class from (a) in this method.

c) When creating a CControl, use one of the constructors with a “CControlFactory” argument and insert the class from (b) there.

  1. When using the EclipseTheme you can have this easier:
    a) Make a new class extending “CommonEclipseThemeConnector” and override the method “getTitleBarKind”. If you get a SplitDockStation in this method, return “TitleBar.NONE”.

b) Use CControl#putProperty and the key EclipseTheme.THEME_CONNECTOR to install your class from (a)