JavaFX中的内部框架 [英] Internal Frames in JavaFX

查看:118
本文介绍了JavaFX中的内部框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了内部框架的这个例子

I found this example of Internal Frames

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

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

Is it possible to make the same internal Frames in JavaFX?

推荐答案

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

With JFXtras there is a Window control, where you can add content and handle the internal window behavior.

首先你需要把在你的classpath中的jfxtras库。他们有一些说明,您可以在这里获得图书馆。如果你正在使用maven,只需要添加:

First you will need to put in your classpath the jfxtras library. They have some instructions where you can get the library. If you are using maven, just need to add:

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

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

Or download the library and put it into your project classpath, whatever.

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

Now I put a sample of the demo of the Window with a little difference, allowing generation of several windows.

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方法中,并且未包含任何按钮。我添加按钮来动态创建窗口并将它们添加到屏幕上。

In the original demo, the event code was in the init method, and no button was included. I add the button to create dynamically windows and adding them to the screen.

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

Here is a snapshot of the result of the application:

我完全是建议你试试jfxtras的演示。他们真的很棒。希望它有所帮助。

I totally recommend you try the demo of jfxtras. They have really great stuff. Hope it helps.

这篇关于JavaFX中的内部框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆