入口代码

package com.company;import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;import java.io.File;
import java.io.FileInputStream;
import java.net.URL;public class Main extends Application {@Overridepublic void start(Stage primaryStage) throws Exception {File file = new File("info/fxml/mainFrame.fxml");URL url = file.toURI().toURL();Parent root = FXMLLoader.load(url);primaryStage.setScene(new Scene(root, 400, 400));primaryStage.setTitle("标题");primaryStage.setResizable(false);primaryStage.getIcons().add(new Image(new FileInputStream("info/img/logo.png")));primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {@Overridepublic void handle(WindowEvent event) {System.out.println("程序退出了");System.exit(0);}});primaryStage.show();}public static void main(String[] args) {launch(args);}}

Controller

package com.company;import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextField;
import javafx.scene.control.ChoiceBox;
import javafx.scene.input.*;import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;public class Controller implements Initializable {@FXML private TextField mubanTextField;@FXML private TextField t_serial_txt;@FXML private TextField t_pdf_path;@FXML private ChoiceBox choiceBoxFiled;@Overridepublic void initialize(URL location, ResourceBundle resources) {t_serial_txt.setText("我支持.txt文件拖入");t_action2(t_serial_txt, ".txt");t_pdf_path.setText("我支持.pdf文件拖入");t_action2(t_pdf_path, ".pdf");//初始化 choiceBoxFiledchoiceBoxFiled.getItems().clear();choiceBoxFiled.getItems().add("123");choiceBoxFiled.getItems().add("456");}private void t_action2(TextField textField, String suffix) {textField.setOnDragOver(new EventHandler<DragEvent>() {@Overridepublic void handle(DragEvent event) {if (event.getGestureSource() != textField) {event.acceptTransferModes(TransferMode.ANY);}}});textField.setOnDragDropped(new EventHandler<DragEvent>() {@Overridepublic void handle(DragEvent event) {Dragboard dragboard = event.getDragboard();if (dragboard.hasFiles()) {try {File file = dragboard.getFiles().get(0);System.out.println(file);if (file != null && file.getName().toLowerCase().indexOf(suffix) != -1) {textField.setText(file.getAbsolutePath());}} catch (Exception e) {e.printStackTrace();}}}});}public void action1(ActionEvent actionEvent) {System.out.println("点击了配置");}public void action2(ActionEvent actionEvent) {System.out.println("点击了教程");}public void work(ActionEvent actionEvent) {System.out.println("点击了生成");}public void checkBoxClick(MouseEvent mouseEvent) {System.out.println("点击了保存模板");}public void keyReleased(KeyEvent keyEvent) {System.out.println("mubanTextField 模板输入框 内容发生了改变:"+mubanTextField.getText());}public void del(ActionEvent actionEvent) {System.out.println("点击了删除模板");}public void open_serial(ActionEvent actionEvent) {System.out.println("点击了打开数据");}
}

目录结构

FXML文件

<?xml version="1.0" encoding="UTF-8"?><?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?><?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.collections.FXCollections?>
<?import java.lang.String?>
<GridPane prefHeight="262.0" style="-fx-pref-width: 400;-fx-font-family: SansSerif" xmlns="http://javafx.com/javafx/8.0.121"xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.company.Controller"><VBox alignment="TOP_LEFT" style="-fx-hgap: 10;-fx-hgap: 10;" GridPane.columnIndex="0" GridPane.columnSpan="2"GridPane.rowIndex="0"><MenuBar fx:id="menuBar" prefHeight="25.0" prefWidth="650"><!-- 设置action实际上是作用于它的MenuItem身上的 --><Menu onAction="#action1" text="配置"><items><MenuItem text="标记"/></items></Menu><Menu onAction="#action2" text="教程"><items><MenuItem text="别看了没有"/></items></Menu></MenuBar></VBox><BorderPane fx:id="borderPane" style="-fx-pref-width: 400px;-fx-max-width: 400px;" GridPane.columnIndex="0" GridPane.rowIndex="1"><center><GridPane style="-fx-hgap: 5;-fx-vgap: 7;-fx-padding: 5;"><Label GridPane.columnIndex="0"  GridPane.rowIndex="0" text="模板" /><TextField fx:id="t_data_txt" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="0" /><Label GridPane.columnIndex="0"  GridPane.rowIndex="1" text="数据"/><TextField fx:id="t_serial_txt" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="1" /><Label GridPane.columnIndex="0"  GridPane.rowIndex="2" text="背景"/><TextField fx:id="t_pdf_path" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="2" /><Label   text="历史模板" GridPane.columnIndex="0"    GridPane.columnSpan="2" GridPane.rowIndex="3"/><ChoiceBox fx:id="choiceBox" prefWidth="190.0" GridPane.columnIndex="2" GridPane.rowIndex="3"><items><FXCollections fx:factory="observableArrayList"><String fx:value="male" /><String fx:value="female" /><String fx:value="unknown" /></FXCollections></items></ChoiceBox><Button fx:id="b_button" onAction="#work" prefWidth="120" text="生成" GridPane.columnIndex="3"GridPane.rowIndex="3"/><CheckBox fx:id="myCheckBox" onMouseClicked="#checkBoxClick" text="保存模板" GridPane.columnIndex="0"  GridPane.columnSpan="2" GridPane.rowIndex="4"/><TextField fx:id="mubanTextField" onKeyReleased="#keyReleased" GridPane.columnIndex="2" GridPane.rowIndex="4"/><Button fx:id="del_button" onAction="#del" prefWidth="120" text="删除模板" GridPane.columnIndex="3"GridPane.rowIndex="4"/><CheckBox fx:id="filedCheckBox" onMouseClicked="#checkBoxClick" text="按列名存"  GridPane.columnIndex="0"    GridPane.columnSpan="2" GridPane.rowIndex="5"/><ChoiceBox fx:id="choiceBoxFiled" prefWidth="190.0" GridPane.columnIndex="2" GridPane.rowIndex="5"><items><FXCollections fx:factory="observableArrayList"><!--<String fx:value="male" />--><!--<String fx:value="female" />--><!--<String fx:value="unknown" />--></FXCollections></items></ChoiceBox><CheckBox fx:id="anshufuzhiCheckBox" onMouseClicked="#checkBoxClick" text="按数复制"  GridPane.columnIndex="0"    GridPane.columnSpan="2" GridPane.rowIndex="6"/><ChoiceBox fx:id="anshufuzhiChoiceBox" prefWidth="190.0" GridPane.columnIndex="2" GridPane.rowIndex="6"><items><FXCollections fx:factory="observableArrayList"><!--<String fx:value="male" />--><!--<String fx:value="female" />--><!--<String fx:value="unknown" />--></FXCollections></items></ChoiceBox><Label GridPane.columnIndex="3"  GridPane.rowIndex="6" text="←选择数量字段"/><Button fx:id="b_button2" onAction="#open_serial" prefWidth="120" text="打开数据" GridPane.columnIndex="3"GridPane.rowIndex="5"/><columnConstraints><ColumnConstraints/><ColumnConstraints/><ColumnConstraints/><ColumnConstraints/></columnConstraints><rowConstraints><RowConstraints/><RowConstraints/><RowConstraints/><RowConstraints/><RowConstraints/><RowConstraints/><RowConstraints/><RowConstraints/></rowConstraints></GridPane></center><bottom><FlowPane fx:id="zs_flowPane" style="max-height: 300; -fx-padding: 5px"><ImageView fx:id="imageView" fitHeight="650.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true" ><image><Image url="@../img/instruction.png"/></image></ImageView></FlowPane></bottom></BorderPane><columnConstraints><ColumnConstraints/><ColumnConstraints/></columnConstraints><rowConstraints><RowConstraints/><RowConstraints/></rowConstraints></GridPane>

javaFX 界面例子相关推荐

  1. javafx 界面_JavaFX的科幻用户界面第1部分

    javafx 界面 使用JavaFX创建的Sci-Fi UI成形窗口 虚构的UI可以变成现实吗? 成长于80年代的小时候,我看到了自己的科幻电影,这确实激发了我对图形用户界面(GUI)的热爱,尤其是试 ...

  2. java调用javafx_Java代码调用JavaFX的例子(大力推荐)

    在JavaFX 1.0发布之后,本人撰写的文章JavaFX和Java之间的互操作性被各网站转载.文中总结了3种从Java调用JavaFX的方法.这三种方法分别为: http://www.javafxb ...

  3. JavaFX界面跳转

    JavaFX界面跳转 界面跳转,很常见的一个功能,在桌面程序中,可以多窗口跳转,也可以在一个窗口中跳转.不同方式对应不同场景.下面简单介绍一下,JavaFX中单窗口界面跳转方式. BorderPane ...

  4. 基于QtQuick2.0开发的诸多漂亮的界面例子(作为入门首选)

    # (持续更新)基于QtQuick2.0开发的诸多漂亮的界面例子(作为入门首选) ![驱动精灵主界面](http://7qn7mv.com1.z0.glb.clouddn.com/qtquickdri ...

  5. javafx项目_爬虫系列(5):JavaFx界面

    接上一节(爬虫系列(4):存储数据-MySQL). 先上图 幻猿·简易爬虫主界面 关于JavaFx JavaFx是在2007年5月的JavaOne大会上公之于众的,而第一个正式版本v1.0是在2008 ...

  6. JavaFx界面设计【SceneBuilder版】适合初学者

    这篇博客主要向大家介绍如何使用javafx制作界面,并只介绍课程设计中用得到的控件~ [关于SceneBuilder软件的安装,大家自行搜索即可,CSDN中有很多教程]

  7. 编写第一个JavaFX界面

    上一篇中我们讲到了关于Java Scene Builder2.0工具的基本使用,这一篇我们来讲讲如何利用IDEA+Java Scene Builder来写一个小界面~~~ 在之前的配置和新建FX项目博 ...

  8. JAVAFX界面跳转和加载不同的界面

    主要分为两种情况 从一个界面跳转到另外一个新的界面 在原有界面上加载其他页面.类似iframe 先从第一个情况的实现说起. 页面跳转 1. 创建一个登录界面 <?xml version=&quo ...

  9. javafx与MySQL的连接_如何让javafx界面直接连接数据库?

    谢邀 首先呢,javaFX是什么,是一个界面框架,这个是什么意思呢,他控制的是用户所看到的东西,显示在屏幕上面的那个窗口,窗口上面的内容,这是javafx负责的地方. 然后呢,数据库,这个是由java ...

最新文章

  1. 【OpenCV 4开发详解】图像直方图绘制
  2. python 等值线 标注 间距、控制_python - Matplotlib-Contourf-如何使刻度线间距不均匀? - 堆栈内存溢出...
  3. Nginx-Lua模块的执行顺序
  4. 怎么能把你的公司快速做大呢
  5. c++ main函数调用 类中的枚举_为什么 Java 的 main 方法必须是 public static void?
  6. “鱼”和“熊掌”也能兼得——省时省心
  7. 使用Nativefier将web页面打包为桌面应用
  8. 数据--第20课-递归的应用实战二
  9. 图神经网络(GCN)
  10. “the import java.io cannot be resolved”错误的解决方法
  11. SHELL下如何去掉字串里的空格(或指定字符)
  12. 2018/3/9 省选模拟赛 0分
  13. cad相对坐标快捷键_cad相对坐标怎么输入?CAD中输入西安80坐标绘图的教程
  14. win10资源管理器频繁重启可能原因及解决方案
  15. 初学者好 |如何从头开始创建一个图像识别的AI应用[ctrl:c+v,你就完成了]
  16. vue中父传子和子传父,传值方法
  17. ligerui demo php,LigerUI的简单使用示例
  18. 详细解释:Epoch、batch_size批处理大小、迭代次数之间的关系
  19. 西行漫记(2):上课第一天
  20. 2022-2028年中国融合通信(UC) 行业市场运行格局及战略咨询研究报告

热门文章

  1. 人民币和美元兑换的编程python_python人民币和美元转换
  2. Docker离线安装及python算法部署详细介绍
  3. 浅谈京东静态html原理,京东首页前端架构设计.ppt
  4. 木马是如何编写的(一)
  5. php找零页面,JS实现找零张数最小
  6. 搭建直播平台什么样的服务器最合适?
  7. jsp text 水印_java实现图片上加文字水印(SpringMVC + Jsp)
  8. 游戏本自动掉帧_LOL官方割韭菜?“永恩上线就出问题,游戏掉帧商城BUG仍未修复”...
  9. lol服务器维护2021,lol维护公告最新时间2021.5.27 lol维护到几点
  10. 微信小程序拼团功能页面展示