JavaFX

maven+IDEA+JavaFX+JFoenix

2018-11-14  本文已影响174人  陶然然_niit

1.maven环境准备

解压apache-maven-3.5.4.zip到D盘根目录,并建一个本地仓库目录my_maven_jar,如图


准备maven和本地仓库目录

2.在IDEA中配置maven环境

3.新建Java项目

新建一个Java项目

4.添加框架支持

5.编码

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.soft1841</groupId>
    <artifactId>first-maven</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>com.jfoenix</groupId>
            <artifactId>jfoenix</artifactId>
            <version>8.0.4</version>
        </dependency>
        <dependency>
            <groupId>io.datafx</groupId>
            <artifactId>datafx</artifactId>
            <version>8.0.1</version>
        </dependency>
        <dependency>
            <groupId>io.datafx</groupId>
            <artifactId>flow</artifactId>
            <version>8.0.1</version>
        </dependency>
        <dependency>
            <groupId>de.jensd</groupId>
            <artifactId>fontawesomefx</artifactId>
            <version>8.9</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.*?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXCheckBox?>
<?import javafx.geometry.Insets?>
<?import com.jfoenix.controls.JFXDatePicker?>
<?import com.jfoenix.controls.JFXTimePicker?>
<StackPane xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="com.maven.test.MyController">
    <HBox spacing="10">
        <JFXButton prefWidth="100" prefHeight="40" buttonType="RAISED" text="BUTTON"
                   style="-fx-font-size:14px;-fx-background-color:WHITE;"/>
        <JFXButton prefWidth="100" prefHeight="40" buttonType="RAISED" text="COLORED" fx:id="dialogButton"
                   style="-fx-text-fill:WHITE;-fx-background-color:#5264AE;-fx-font-size:14px;"/>
        <JFXButton prefWidth="100" prefHeight="40" buttonType="RAISED" text="DISABLED"
                   style="-fx-background-color:WHITE;-fx-font-size:14px;" disable="true"/>
        <JFXCheckBox text="Notifications" styleClass="custom-jfx-check-box"></JFXCheckBox>
        <JFXCheckBox text="Auto Updates" styleClass="custom-jfx-check-box-all-colored"></JFXCheckBox>
    <padding>
        <Insets top="10" left="20"/>
    </padding>
    </HBox>
    <HBox spacing="40" style="-fx-padding: 100 0 0 50;">
        <children>
          <JFXDatePicker fx:id="dateOverlay" overLay="true"
                                   styleClass="custom-color-picker"></JFXDatePicker>
          <JFXTimePicker fx:id="timeOverlay" overLay="true"
                                   styleClass="custom-color-picker"></JFXTimePicker>
       </children>
     </HBox>
</StackPane>

package com.maven.test;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MyApp extends Application {
   @Override
   public void start(Stage primaryStage) throws Exception {
       Parent root = FXMLLoader.load(getClass().getResource("/fxml/main.fxml"));
       primaryStage.setTitle("maven项目");
       Scene scene = new Scene(root, 900, 500);
       scene.getStylesheets().add(MyApp.class.getResource("/css/jfoenix-components.css").toExternalForm());
       primaryStage.setScene(scene);
       primaryStage.show();
   }

   public static void main(String[] args) {
       launch(args);
   }
}

时间组件

6.所需资源下载

上一篇下一篇

猜你喜欢

热点阅读