加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

javafx-2 – JavaFX中的内部框架

发布时间:2020-12-14 23:21:02 所属栏目:Java 来源:网络整理
导读:我找到了内部框架的这个例子 http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html 是否可以在JavaFX中创建相同的内部框架? 解决方法 使用 JFXtras,有一个Window控件,您可以在其中添加内容并处理内部窗口行为. 首先,您需要在类路
我找到了内部框架的这个例子

http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html

是否可以在JavaFX中创建相同的内部框架?

解决方法

使用 JFXtras,有一个Window控件,您可以在其中添加内容并处理内部窗口行为.

首先,您需要在类路径中放入jfxtras库.他们有一些说明,您可以在这里获得图书馆.如果您使用的是maven,只需添加:

<dependency>
    <groupId>org.jfxtras</groupId>
    <artifactId>jfxtras-labs</artifactId>
    <version>2.2-r5</version>
</dependency>

或者下载库并将其放入项目类路径中,无论如何.

现在我把Window的演示样本略有不同,允许生成几个窗口.

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.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 WindowTests extends Application {
private static int counter = 1;

private void init(Stage primaryStage) {
    final Group root = new Group();

    Button button = new Button("Add more windows");     

    root.getChildren().addAll(button);
    primaryStage.setResizable(false);
    primaryStage.setScene(new Scene(root,600,500));

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

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

在原始演示中,事件代码位于init方法中,并且未包含任何按钮.我添加按钮以动态创建窗口并将其添加到屏幕.

以下是应用程序结果的快照:

我完全建议你试试jfxtras的演示.他们真的很棒.希望能帮助到你.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读