簡體   English   中英

Javafx可拆卸窗格系統

[英]Javafx detachable pane system

這是我喜歡的,我在幾個不同的軟件中看到過。 我不知道它的起源或實際的名稱,但這里是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");
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM