我找到了这个内部框架的例子
http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html
是否可以在 JavaFX 中制作相同的内部框架?
最佳答案
与 JFXtras有一个窗口控件,您可以在其中添加内容并处理内部窗口行为。
首先,您需要将 jfxtras 库放入类路径中。他们有一些说明,您可以在其中获取图书馆。如果使用maven,只需要添加:
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-labs</artifactId>
<version>2.2-r5</version>
</dependency>
或者下载库并将其放入您的项目类路径中,等等。
现在我放了一个稍有不同的窗口演示示例,允许生成多个窗口。
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 的演示。他们有很棒的东西。希望对您有所帮助。
关于javafx-2 - JavaFX 中的内部框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17673292/