Javafx 可拆卸窗格系统

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22432811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:40:48  来源:igfitidea点击:

Javafx detachable pane system

javajavafx

提问by Nicolas Martel

This is something I like that I have seen in a few different softwares. I don't know where it originates from or what it really is called but here is an example of the pane system in Visual Studio.

这是我在一些不同的软件中看到的我喜欢的东西。我不知道它的起源或真正的名称,但这里是 Visual Studio 中窗格系统的一个示例。

enter image description here

在此处输入图片说明

Note how I can easily attach the pane anywhere with ease. Is such a thing possible with Javafx?

请注意我如何轻松轻松地将窗格附加到任何地方。Javafx 可以实现这样的事情吗?

采纳答案by Goombert

I recognize this question is old but others may be interested to know. I created a lightweight docking library for JavaFX for both proprietary and non-proprietary uses under the LGPL license.

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

https://github.com/RobertBColton/DockFX

https://github.com/RobertBColton/DockFX

enter image description here

在此处输入图片说明

回答by jewelsea

There is no built-in docking framework for JavaFX 8.

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

There are some 3rd party solutions such as Drombler FX. I haven't used any of them.

有一些 3rd 方解决方案,例如Drombler FX。我没有使用过它们中的任何一个。

A simple home-built system to dock and undock panels is pretty easy to create, but a comprehensive system would be quite difficult. The following code is adapted from zonski's answer to a docking framework discussion is in the Oracle JavaFX forum threads.

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

dockedundocked

停靠未对接

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);
    }
}

If you have extensiveneed for such a framework, you might want to look into the NetBeans platform, which is a Swing based framework into which you can embed JavaFX.

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

回答by Pete

As the previous answersays, JavaFX does not have built-in support for dockable tabs. There is an OpenJDK issuerequesting support for draggable and dockable tabs.

正如前面的答案所说,JavaFX 没有对可停靠选项卡的内置支持。有一个OpenJDK 问题要求支持可拖动和可停靠的选项卡。

A recent third-party solution that may be worth looking into is DockFXwhich is in active development at the time of writing (September 2015)

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

回答by andy goryachev

A simple docking framework for JavaFX:

一个简单的 JavaFX 对接框架:

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

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");
    }
}