This is different from Move dockable to other CContentArea?.
I have two JFrame
s, each with a CContentArea
. I create two DefaultSingleCDockable
s. Both dockables appear in the same content area:
I can use the mouse to drag and drop Dockable 2 into JFrame 2:
How can I move Dockable 2 into JFrame 2 using code?
Complete example code:
import bibliothek.gui.dock.common.CContentArea;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
public class MoveDockable {
private final static int JFRAME_WIDTH = 300;
private final static int JFRAME_HEIGHT = 400;
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame jFrame1 = new JFrame("JFrame 1");
jFrame1.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jFrame1.getContentPane().setLayout(new BorderLayout());
jFrame1.setSize(JFRAME_WIDTH, JFRAME_HEIGHT);
jFrame1.setLocation(0, 0);
CControl cControl = new CControl(jFrame1);
CContentArea contentArea1 = cControl.createContentArea("contentAreaID1");
jFrame1.getContentPane().add(contentArea1);
DefaultSingleCDockable dockable1 = new DefaultSingleCDockable(
"dockableID1", "Dockable 1", new JLabel("Contents of dockable 1"));
cControl.addDockable(dockable1);
dockable1.setVisible(true);
jFrame1.setVisible(true);
JFrame jFrame2 = new JFrame("JFrame 2");
jFrame2.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jFrame2.getContentPane().setLayout(new BorderLayout());
jFrame2.setSize(JFRAME_WIDTH, JFRAME_HEIGHT);
jFrame2.setLocation(JFRAME_WIDTH, 0);
CContentArea contentArea2 = cControl.createContentArea("contentAreaID2");
jFrame2.getContentPane().add(contentArea2);
DefaultSingleCDockable dockable2 = new DefaultSingleCDockable(
"dockableID2", "Dockable 2", new JLabel("Contents of dockable 2"));
cControl.addDockable(dockable2);
dockable2.setVisible(true);
jFrame2.setVisible(true);
});
}
}
None of these lines do what I want:
dockable2.setLocation(contentArea2.getCenterArea().getAutoBaseLocation(true));
dockable2.setLocation(contentArea2.getCenterArea().getAutoBaseLocation(false));
dockable2.setLocation(contentArea2.getCenterArea().getBaseLocation());
dockable2.setLocation(contentArea2.getCenterArea().getDropLocation());
dockable2.setLocation(contentArea2.getCenterArea().getStationLocation());