Can I create a DockFrontend without a JFrame?


I am using DockingFrames in a scenario where the JFrame instance is not known when I initialize DockingFrames and create a default layout by dropping components.

I am able to create a DockFrontend without giving it the JFrame instance, however, when I add multiple dockables, the actual window shows only the first dockable.

Here’s how I create the DockFrontend. The JFrame instance is created in the display() method.

_frontend = new DockFrontend();
DockTheme theme = new FlatTheme();
//set the Theme
_frontend.getController().setTheme(new NoStackTheme(theme));
_defaultStation = new SplitDockStation();
_frontend.addRoot(_defaultStation, "DefaultStation");
_factory = new LbViewFactory();

Here is the createDefaultLayout() method.

private void createDefaultLayout()
        LbViewFactory.LbView gridView = 
        _frontend. add(gridView, LbViewFactory.DockableEnum.GRID.getTitle());
        LbViewFactory.LbView formulaEditorView = 
        _defaultStation.drop(formulaEditorView, SplitDockProperty.SOUTH);
        LbViewFactory.LbView bcpView = 
        _defaultStation.drop(bcpView,    SplitDockProperty.WEST);

I am adding 3 components to the _defaultStation. However, only the first one is displayed.

If I create the JFrame before creating the DockFrontend and give DockFrontend an instance of JFrame, then the app works fine.

Is it possible to get this to work such that the DockFrontend does not have to know of JFrame at initialization time?


I would recommend using a SplitDockTree or SplitDockGrid. But if that is not an option for you, than try SplitDockPathProperty instead of SplitDockProperty. This path-property can inserts a new Dockable at any valid location in the tree that represents the internal organization of SplitDockStation. The code looks not as nice as before, but it should work better:
(btw: you have just discovered a bug, congratulations :o) )

import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JPanel;

import bibliothek.extension.gui.dock.theme.EclipseTheme;
import bibliothek.gui.DockFrontend;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.DefaultDockable;
import bibliothek.gui.dock.SplitDockStation;
import bibliothek.gui.dock.station.split.SplitDockPathProperty;

public class Dock2 {
        public static void main( String[] args ){
                DockFrontend frontend = new DockFrontend();
                frontend.getController().setTheme( new EclipseTheme() );
                SplitDockStation station = new SplitDockStation();
                frontend.addRoot( station, "station" );
                station.drop(  createDockable( "Green", Color.GREEN ) );
                station.drop(  createDockable( "Yellow", Color.YELLOW ), SplitDockProperty.SOUTH );
                station.drop(  createDockable( "Blue", Color.BLUE ), SplitDockProperty.EAST );
                // */
                // interesting part starts here
                station.drop(  createDockable( "Green", Color.GREEN ) );
                SplitDockPathProperty path = new SplitDockPathProperty();
                path.add( SplitDockPathProperty.Location.BOTTOM, 0.25 );
                station.drop(  createDockable( "Yellow", Color.YELLOW ), path );
                path = new SplitDockPathProperty();
                path.add( SplitDockPathProperty.Location.RIGHT, 0.25 );
                station.drop(  createDockable( "Blue", Color.BLUE ), path );
                // interesting part ends here
                // */
                JFrame frame = new JFrame( "Demo" );
                frame.add( station.getComponent() );
                frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
                frame.setBounds( 20, 20, 400, 400 );
                frame.setVisible( true );
        public static Dockable createDockable( String title, Color color ){
                JPanel panel = new JPanel();
                panel.setOpaque( true );
                panel.setBackground( color );
                return new DefaultDockable( panel, title );

Thanks, using SplitDockPathProperty helped solve the issue.