Change the background colro of a CContentArea

Hi,

CContentArea is a JPanel; I want to change the background color of it; I tried:

  1. control.getContentArea().setBackgroundColor(Color.Blue) --> It doesn’t work
  2. setting the background color of all inner station, it contains --> It doesn’t work

[SIZE=2]control[/SIZE].getContentArea().getNorth().getComponent().setBackground(Color.**[SIZE=2]YELLOW[/SIZE]**);
[SIZE=2]control[/SIZE].getContentArea().getCenter().getComponent().setBackground(Color.**[SIZE=2]YELLOW[/SIZE]**);
[SIZE=2]control[/SIZE].getContentArea().getSouth().getComponent().setBackground(Color.**[SIZE=2]YELLOW[/SIZE]**);
[SIZE=2]control[/SIZE].getContentArea().getWest().getComponent().setBackground(Color.**[SIZE=2]YELLOW[/SIZE]**);
[SIZE=2]control[/SIZE].getContentArea().getEast().getComponent().setBackground(Color.**[SIZE=2]YELLOW[/SIZE]**);

[LEFT]Could you please advice?[/LEFT]

[LEFT]Thank you[/LEFT]

Using the newest version: IMHO the easiest solution to accomplish your goal is to implement a new “BackgroundPaint”. Then access the ThemeManager (DockController.getThemeManager) and call “setBackgroundPaint” with the identifiers “.station.flap" and ".station.split” where * is “ThemeManager.BACKGROUND_PAINT”.

Your BackgroundPaint would not need to do much. It would look somewhat like this:

  public void paint( BackgroundComponent background, PaintableComponent paintable, Graphics g ){
    paintable.paintBackground( null );
    g.setColor( ... );
    Component component = paintable.getComponent();
    g.fillRect( 0, 0, component.getWidth(), component.getHeight() );
  }
}```

Currently I'm at work, but  if you wish I can write a working example later.

I’m not able to find the BackgroundPaint class in either core or common.

How would I change the paint of the CControlArea? Preferably to a gradient?

You need to have version 1.1.0p3 (better use 1.1.0p6) in order to find BackgroundPaint, version 1.0.8 is too old. It would then be in Core.

As for the gradient: search for the class “BackgroundExample” which is in the project “tutorial” (also only in version 1.1.0). This example paints an image as background, it should give you a starting point. You would need to calculate the position of the Component that is painted in relation to some basic coordinate system (e.g. your JFrame), and then adjust the painting code to the offset. Exactly the same does the BackgroundExample on lines 161-170.

Painting a gradient can be done with GradientPaint, a standard class in the JRE.

Working on it right now. But would it be possible to make the background transparent?

Not in the current version. In theory the interfaces could be extended to allow that, but that would be a lot of work and I would like to finish 1.1.0 before starting the next big chunk. I’ll keep it in the todo-list, but you won’t see the feature in the near future.

As a workaround I can only offer something like the BackgroundExample: painting pieces of an image to produce a fake transparency effect.

[Edit: you could recursively visit all the JComponents and switch the opaque flag where necessary. I don’t know how much work that would be and how well it would work, but I guess you could make all Components transparent that way. With some ContainerListeners you would always be informed if a new JComponent was added to the tree of Components.]

That’s perfectly ok. Now I know within what limits I have to work.

Oh, one more simple question: increasing the inner gap size (spacing between the dockables). Is that possible?

That is possible through the method “SplitDockStation.setDividerSize” or “CContentArea.getCenter().setDividerSize(…)” (which is the same).

Hi,

How to get the ThemeManager from the CControl?

In the core library It is :


controller.getThemeManager().setBackgroundPaint( ThemeManager.**[SIZE=2]BACKGROUND_PAINT**[/SIZE] + [SIZE=2]".custom"[/SIZE], **[SIZE=2]new**[/SIZE] CustomPaint() );

Is there a way to set the background color of a CContentArea upen its creation?

Thank you

with one of the newer versions:

control.getController().getThemeManager...```

CContentArea is a JPanel with some stations on it, it is completely covered with its children and thus not really visible. Hence the solution would be to modify these stations, and that is done in the exact same way as you would do it in Core (the children are all of type FlapDockStation and SplitDockStation).