当前位置: 首页 > 知识库问答 >
问题:

JavaFX中的内部框架

云承天
2023-03-14

是否可以在JavaFX中制作相同的内部帧?

共有1个答案

沈飞跃
2023-03-14

对于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);}
}
 类似资料:
  • 我真的很感谢你帮我解决问题。 我正在使用JavaFX和NetBeans IDE。我正在为桌面客户端制作一个非常简单的启动窗口。窗口当前与此图像类似。 当前外观: null 我有一个GridPane作为根。不知道为什么JavaFX选择使用(col,row),但这就是我在下面表示我的设置的方式: @GridPane(0,0)->“欢迎”文本 @GridPane(0,1)->VBox(此VBox包含上图

  • 我正在使用和。 我想锁定JDesktopPane内部的内部框架。 建议需要更改的方法或属性。

  • 提前谢了。

  • 我正在建立一个简单的可编辑组合框与自动完成。我想根据内部TextField的内容筛选组合框的内容。 我设法使其工作,但当从TextField中删除字符时,我面临一个重新应用自动完成逻辑的问题。 从我所看到的情况来看,在按下键的事件上,文本字段的内容还不包含添加的字符。 所以我只是做了一个简单的逻辑来添加KeyEvent的字符串版本来模拟TextField的内容。我制作了这个灯塔,我需要有全文来应用

  • 我最近从c#转向尝试Javafx2。我也是这个论坛的新手。我一直在尝试在Javafx中实现内部框架。我偶然发现了这个链接:JavaFX中的内部框架我设法将jfxtras 8 jar文件添加到我的项目以及场景构建器2中。但是,我被困在对齐窗口上的控件上。 这是fxml文件代码: 这是控制器类代码: 现在,有人知道我如何能够对齐标签,使其文本显示在按钮下方吗?当点击按钮时,标签上的文字会出现在按钮上方