[英]Javafx detachable pane system
這是我喜歡的,我在幾個不同的軟件中看到過。 我不知道它的起源或實際的名稱,但這里是Visual Studio中窗格系統的一個示例。
請注意我如何輕松地將窗格輕松附加到任何位置。 Javafx有可能這樣嗎?
我知道這個問題很老,但其他人可能有興趣知道。 我為JavaFX創建了一個輕量級的對接庫,用於LGPL許可下的專有和非專有用途。
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的簡單對接框架:
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.