Fix size DefaultDockable

Hi,
I have the simple code


package com.bis.template2;

import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

import bibliothek.gui.DockFrontend;
import bibliothek.gui.dock.DefaultDockable;
import bibliothek.gui.dock.SplitDockStation;
import bibliothek.gui.dock.station.split.SplitDockGrid;

public class Test extends JFrame {

	private static final long serialVersionUID = 1L;

	public Test() {
		super("Template");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		buildGUI();
	}

	private void buildGUI() {
		setSize(600, 600);
		JPanel main = new JPanel();
		main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
		main.add(buildContent());
		add(main);
		setVisible(true);
	}

	private JComponent buildContent() {

		DockFrontend frontend = new DockFrontend(this);
		SplitDockStation station = new SplitDockStation();

		frontend.addRoot("station", station);
		frontend.setShowHideAction(true);

		ColorDockable left1 = new ColorDockable("Left1");
		ColorDockable left2 = new ColorDockable("Left2");

		frontend.addDockable("left1", left1);
		frontend.setHideable(left1, true);
		frontend.addDockable("left2", left2);
		frontend.setHideable(left2, true);

		SplitDockGrid grid = new SplitDockGrid();
		grid.addDockable(1, 1, 1, 1, left1);
		grid.addDockable(2, 1, 1, 1, left2);
		station.dropTree(grid.toTree());
		return station;
	}

	private class ColorDockable extends DefaultDockable {
		private JPanel panel;

		public ColorDockable(String title) {
			setTitleText(title);
			panel = new JPanel();
			panel.setOpaque(true);
		}
	}

	public static void main(String[] args) {
		new Test();
	}

}

And i’m trying to fix size of DefaultDockable. Is it possible?

I found workaround station.setResizingEnabled(false);, it`s help to freeze station.
But i have one more question

Q. How can i to restricted place where my Dockable can be droped.

Code


package com.bis.frame;

import java.awt.Color;

import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

import bibliothek.extension.gui.dock.theme.EclipseTheme;
import bibliothek.extension.gui.dock.theme.eclipse.displayer.EclipseDisplayerFactory;
import bibliothek.gui.DockController;
import bibliothek.gui.DockFrontend;
import bibliothek.gui.DockStation;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.SplitDockStation;
import bibliothek.gui.dock.station.DockableDisplayer;
import bibliothek.gui.dock.station.split.SplitDockGrid;
import bibliothek.gui.dock.title.DockTitle;

public class MainFrame extends JFrame {

	private static final long serialVersionUID = 1L;

	public MainFrame() {
		super("MainFrame");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		buildGUI();
	}

	private void buildGUI() {
		setSize(800, 600);
		JPanel main = new JPanel();
		main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
		main.add(buildContent());
		add(main);
		setVisible(true);
	}

	private JComponent buildContent() {
		final DockFrontend frontend = new DockFrontend(this);
		SplitDockStation station = new SplitDockStation();
		station.setResizingEnabled(false);
		SplitDockGrid grid = new SplitDockGrid();

		frontend.addRoot("station", station);
		frontend.setShowHideAction(true);

		VerticalPane left1 = new VerticalPane("Left1", Color.RED);
		frontend.addDockable("left1", left1);
		frontend.setHideable(left1, true);
		grid.addDockable(1, 1, 1, 1, left1);
		
		final VerticalPane center = new VerticalPane("center", Color.BLUE);
		frontend.addDockable("center", center);
		frontend.setHideable(center, true);
		grid.addDockable(2, 1, 1, 1, center);

		VerticalPane right = new VerticalPane("right", Color.BLUE);
		frontend.addDockable("right", right);
		frontend.setHideable(right, true);
		grid.addDockable(3, 1, 1, 1, right);
		
		VerticalPane bottom = new VerticalPane("bottom", Color.BLUE);
		frontend.addDockable("bottom", bottom);
		frontend.setHideable(bottom, true);
		grid.addDockable(1, 2, 3, 0.1, bottom);

		EclipseTheme theme = new EclipseTheme();
		DockController sa = frontend.getController();
	

		theme.setDisplayerFactory(new EclipseDisplayerFactory(theme) {
			@Override
			public DockableDisplayer create(DockStation station, Dockable dockable, DockTitle title) {
				if (dockable == center) {
					return new ThickBorderDisplayer(frontend.getController(), station, dockable);
				}
				return super.create(station, dockable, title);
			}
		});
		
		frontend.getController().setTheme(theme);
		station.dropTree(grid.toTree());
		return station;
	}
	
	
}

I want to move right panel to left and disable move right/left panels to the bottom place.

In general the framework is about giving the user the freedom to arrange the layout of his application in any way he likes. As a result restrictions like “cannot resize” and “can move only to certain locations” are not supported. And there are no plans to support these restrictions in the future.

But there are some less restricting versions of what you describe:

About the size: If you were using the Common project (which I recommend), you could use “CDockable.setResizeLocked”. If enabled, the framework tries to keep the size of a Dockable, but the user is still allowed to resize the Dockable directly. In the Core project such a functionality does not exist.

About the place: you could prevent the bottom Dockable to be combined (stacked) with any other Dockable. In Common you would call “CDockable.setStackeable(false)” (*). But for a SplitDockStation there are no things like “left” or “right”, you would need to modify the SplitDockStation directly to really prevent a Dockable from going at the “bottom”. And believe me: that’s something that will keep you awake for several days.

(*) In Core you would need to write a custom DockAcceptance whose second “accept” method returns false whenever the bottom Dockable shows up as argument. You could register the new DockAcceptance with “DockController.addAcceptance”.

Can i use CDockable with close button?

Yes, every CDockable automatically gets a close button.

If you use the Common project you get everything what DockFrontend offers + some additional features.