javafx自定义窗体(高级篇)
javafx的窗体可以有多种形式存在,官方的提供一些风格可以在我的第一篇文章javafx窗口风格、包括自定义标题栏获取到,如果有不了解的可以先从我的第一篇文章了解。今天这篇文章要说的是如果自定义一个全新的窗体,完全是自己的风格的,不带javafx原生的任何修饰。先看看效果图:
直接上代码
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class CustomWindowDemo extends Application {
private double x = 0.00;
private double y = 0.00;
private double width = 0.00;
private double height = 0.00;
private boolean isMax = false;
private boolean isRight;// 是否处于右边界调整窗口状态
private boolean isBottomRight;// 是否处于右下角调整窗口状态
private boolean isBottom;// 是否处于下边界调整窗口状态
private double RESIZE_WIDTH = 5.00;
private double MIN_WIDTH = 400.00;
private double MIN_HEIGHT = 300.00;
private double xOffset = 0, yOffset = 0;//自定义dialog移动横纵坐标
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.initStyle(StageStyle.TRANSPARENT);
BorderPane root = new BorderPane();
GridPane gpTitle = new GridPane();
gpTitle.setAlignment(Pos.CENTER_LEFT);
gpTitle.setPadding(new Insets(10)