Javafx可拆卸窗格系统

这是我喜欢的,我在几个不同的软件中看到过。 我不知道它的起源或实际调用内容,但这里是Visual Studio中窗格系统的一个示例。

在此处输入图像描述

请注意我如何轻松地将窗格轻松附加到任何位置。 Javafx有可能这样吗?

我知道这个问题很老,但其他人可能有兴趣知道。 我为JavaFX创建了一个轻量级的对接库,用于LGPL许可下的专有和非专有用途。

https://github.com/RobertBColton/DockFX

在此处输入图像描述

JavaFX 8没有内置的对接框架。

还有一些第三方解决方案,如Drombler FX 。 我没有用过任何一个。

一个简单的自制系统,用于停靠和取消停靠面板很容易创建,但是一个全面的系统将非常困难。 以下代码改编自zonski对Oracle JavaFX论坛主题中对接框架讨论的回答。

停靠出坞

import javafx.application.Application; import javafx.geometry.Orientation; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class SimpleDocking extends Application { public void start(final Stage stage) throws Exception { final SplitPane rootPane = new SplitPane(); rootPane.setOrientation(Orientation.VERTICAL); final FlowPane dockedArea = new FlowPane(); dockedArea.getChildren().add(new Label("Some docked content")); final FlowPane centerArea = new FlowPane(); final Button undockButton = new Button("Undock"); centerArea.getChildren().add(undockButton); rootPane.getItems().addAll(centerArea, dockedArea); stage.setScene(new Scene(rootPane, 300, 300)); stage.show(); final Dialog dialog = new Dialog(stage); undockButton.disableProperty().bind(dialog.showingProperty()); undockButton.setOnAction(actionEvent -> { rootPane.getItems().remove(dockedArea); dialog.setOnHidden(windowEvent -> { rootPane.getItems().add(dockedArea); }); dialog.setContent(dockedArea); dialog.show(stage); }); } private class Dialog extends Popup { private BorderPane root; private Dialog(Window parent) { root = new BorderPane(); root.setPrefSize(200, 200); root.setStyle("-fx-border-width: 1; -fx-border-color: gray"); root.setTop(buildTitleBar()); setX(parent.getX() + 50); setY(parent.getY() + 50); getContent().add(root); } public void setContent(Node content) { root.setCenter(content); } private Node buildTitleBar() { BorderPane pane = new BorderPane(); pane.setStyle("-fx-background-color: burlywood; -fx-padding: 5"); final Delta dragDelta = new Delta(); pane.setOnMousePressed(mouseEvent -> { dragDelta.x = getX() - mouseEvent.getScreenX(); dragDelta.y = getY() - mouseEvent.getScreenY(); }); pane.setOnMouseDragged(mouseEvent -> { setX(mouseEvent.getScreenX() + dragDelta.x); setY(mouseEvent.getScreenY() + dragDelta.y); }); Label title = new Label("My Dialog"); title.setStyle("-fx-text-fill: midnightblue;"); pane.setLeft(title); Button closeButton = new Button("X"); closeButton.setOnAction(actionEvent -> hide()); pane.setRight(closeButton); return pane; } } private static class Delta { double x, y; } public static void main(String[] args) throws Exception { launch(args); } } 

如果您对此类框架有广泛的需求,您可能需要查看NetBeans平台 ,这是一个基于Swing的框架,您可以在其中嵌入JavaFX。

如前面的答案所述 ,JavaFX没有可停靠标签的内置支持。 有一个OpenJDK问题请求支持可拖动和可停靠的选项卡。

最近可能值得研究的第三方解决方案是DockFX ,它在撰写本文时处于积极开发阶段(2015年9月)

JavaFX的简单对接框架:

https://github.com/andy-goryachev/FxDock

 public void start(Stage s) throws Exception { // plug in custom windows and dockable panes. FxDockFramework.setGenerator(new DemoPanes()); // load saved layout int ct = FxDockFramework.loadLayout(); if(ct == 0) { // when no saved layout exists, open the first window DemoWindow.openBrowser("https://github.com/andy-goryachev/FxDock"); } }