0

我需要通过单击一个按钮在 TabPane 中显示一个或多个阶段,如下图所示

在此处输入图像描述

我的目标是在 Swing 中出现类似于 JInternalFrame 的情况:如何做到这一点?我无法将阶段作为子项添加到选项卡窗格。

如果这是不可能的,还有什么其他解决方案?我想让SplitPanes 出现在舞台上。

谢谢

PS 我使用的是 Win7、NetBeans 7.4 Beta (Build 201307092200)、SceneBuilder 1.1

编辑:这是一些 VFXWindows css 更改后的外观

在此处输入图像描述

有一点值得注意:我必须添加一个节点(在我的例子中是一个带有 prefSize(0,0) 的 HBox,否则我无法移动或调整绘制的第一个窗口的大小,只有第一个窗口。

最后,我找不到设置窗口全屏(最大化)的方法。

4

1 回答 1

3

这里我在 Tabs 中放了一个来自jfxtras的窗口示例,我只是修改了示例

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.stage.Stage;
import jfxtras.labs.scene.control.window.CloseIcon;
import jfxtras.labs.scene.control.window.MinimizeIcon;
import jfxtras.labs.scene.control.window.Window;


public class WindowInTab extends Application {
private static int counter = 1;

private void init(Stage primaryStage) {
    TabPane tabPane = new TabPane();
    Tab tab = generateTab("Windows...");        
    Tab anotherTab = generateTab("More Windows");
    tabPane.getTabs().addAll(tab, anotherTab);      
    primaryStage.setResizable(true);
    primaryStage.setScene(new Scene(tabPane, 600, 500));        
}

private Tab generateTab(String tabName) {
    Tab tab = new Tab(tabName);
    final Group root = new Group();
    tab.setContent(root);
    Button button = new Button("Add more windows");     

    root.getChildren().addAll(button);      

    button.setOnAction(new EventHandler<ActionEvent>() {            
        @Override
        public void handle(ActionEvent arg0) {
            // create a window with title "My Window"
            Window w = new Window("My Window#"+counter);
            // set the window position to 10,10 (coordinates inside canvas)
            w.setLayoutX(10);
            w.setLayoutY(10);
            // define the initial window size
            w.setPrefSize(300, 200);
            // either to the left
            w.getLeftIcons().add(new CloseIcon(w));
            // .. or to the right
            w.getRightIcons().add(new MinimizeIcon(w));
            // add some content
            w.getContentPane().getChildren().add(new Label("Content... \nof the window#"+counter++));
            // add the window to the canvas
            root.getChildren().add(w);  
        }
    });
    return tab;
}

public double getSampleWidth() {return 600;}
public double getSampleHeight() {return 500;}

@Override
public void start(Stage primaryStage) throws Exception {
    init(primaryStage);
    primaryStage.show();
}
public static void main(String[] args) {launch(args);}

}

选项卡中的内部窗口

我不知道这是否正是你要找的。希望能帮助到你!

于 2013-07-24T14:15:23.783 回答