JAVAFX纯手写布局

主页面效果:

JAVAFX纯手写布局_第1张图片

第一栏的效果:

JAVAFX纯手写布局_第2张图片

JAVAFX纯手写布局_第3张图片

工程目录:

JAVAFX纯手写布局_第4张图片

package MessageBean;

/**
 *
 * @author novo
 */
public class Message {
    private String MMQBH;  //密码器编号
    private String SCCS;   //生产厂商
    private String ZT;    //密码器状态
    private int KHH;      //客户号
    private String KHMC;  //客户名称
    private String BHFX;  //是否本行发行
    private String FXRQ;  //发行登记日期
    private String CJR;   //创建人
    public Message(){};
    public Message(String MMQBH,String SCCS,String ZT,int KHH,String KHMC,String BHFX,String FXRQ,String CJR){
        this.MMQBH = MMQBH;
        this.SCCS = SCCS;
        this.ZT = ZT;
        this.KHH = KHH;
        this.KHMC = KHMC;
        this.BHFX = BHFX;
        this.FXRQ = FXRQ;
        this.CJR = CJR;
    };
    /**
     * @return the MMQBH
     */
    public String getMMQBH() {
        return MMQBH;
    }

    /**
     * @param MMQBH the MMQBH to set
     */
    public void setMMQBH(String MMQBH) {
        this.MMQBH = MMQBH;
    }

    /**
     * @return the SCCS
     */
    public String getSCCS() {
        return SCCS;
    }

    /**
     * @param SCCS the SCCS to set
     */
    public void setSCCS(String SCCS) {
        this.SCCS = SCCS;
    }

    /**
     * @return the ZT
     */
    public String getZT() {
        return ZT;
    }

    /**
     * @param ZT the ZT to set
     */
    public void setZT(String ZT) {
        this.ZT = ZT;
    }

    /**
     * @return the KHH
     */
    public int getKHH() {
        return KHH;
    }

    /**
     * @param KHH the KHH to set
     */
    public void setKHH(int KHH) {
        this.KHH = KHH;
    }

    /**
     * @return the KHMC
     */
    public String getKHMC() {
        return KHMC;
    }

    /**
     * @param KHMC the KHMC to set
     */
    public void setKHMC(String KHMC) {
        this.KHMC = KHMC;
    }

    /**
     * @return the BHFX
     */
    public String getBHFX() {
        return BHFX;
    }

    /**
     * @param BHFX the BHFX to set
     */
    public void setBHFX(String BHFX) {
        this.BHFX = BHFX;
    }

    /**
     * @return the FXRQ
     */
    public String getFXRQ() {
        return FXRQ;
    }

    /**
     * @param FXRQ the FXRQ to set
     */
    public void setFXRQ(String FXRQ) {
        this.FXRQ = FXRQ;
    }

    /**
     * @return the CJR
     */
    public String getCJR() {
        return CJR;
    }

    /**
     * @param CJR the CJR to set
     */
    public void setCJR(String CJR) {
        this.CJR = CJR;
    }
    
}

package Message;

import MessageBean.Message;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;

/**
 *
 * @author Administrator
 */
public  class JsonMethod {
    public static ObservableList getList(){
        ObservableList list = FXCollections.observableArrayList();
        Message msg1 = new Message();
        msg1.setMMQBH("12453464");
        msg1.setSCCS("四川xx");
        msg1.setZT("正常");
        msg1.setKHH(1001);
        msg1.setKHMC("zhangsan");
        msg1.setBHFX("是");
        msg1.setFXRQ("2013-08-20 10:09:25");
        msg1.setCJR("test1");
        
        Message msg2 = new Message();
        msg2.setMMQBH("8765432");
        msg2.setSCCS("四川xx");
        msg2.setZT("锁定");
        msg2.setKHH(1090);
        msg2.setKHMC("lisi");
        msg2.setBHFX("是");
        msg2.setFXRQ("2013-08-20 18:09:25");
        msg2.setCJR("test4");
        
        list.add(msg1);
        list.add(msg2);
        return list;
    }
}

package mylayoutsample;

import Message.JsonMethod;
import MessageBean.Message;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Accordion;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.stage.Stage;

/**
 *
 * @author novo
 */
public class MyLayoutsample extends Application {
    public Button tree1btn1 = new Button();
    public Button tree1btn2 = new Button();
    
    public Button tree2btn1 = new Button();
    public Button tree2btn2 = new Button();
    public Button tree2btn3 = new Button();
    public Button tree2btn4 = new Button();
    
    public Button tree3btn1 = new Button();
    public Button tree3btn2 = new Button();
    public Button tree3btn3 = new Button();
    public Button tree3btn4 = new Button();
    
    public Button tree4btn1 = new Button();
    public Button tree4btn2 = new Button();
    public Button tree4btn3 = new Button();
    public Button tree4btn4 = new Button();
    public Button tree4btn5 = new Button();
    
    /**
     * 设置根节点布局
     * @return 返回布局
     */
    public BorderPane setBorder(){
        BorderPane layout = new BorderPane();
//        layout.setTop(new Rectangle(200, 50, Color.DARKCYAN));
//        layout.setBottom(new Rectangle(200, 50, Color.DARKCYAN));
//        layout.setCenter(new Rectangle(100, 100, Color.MEDIUMAQUAMARINE));
//        layout.setLeft(new Rectangle(50, 100, Color.DARKTURQUOISE));
//        layout.setRight(new Rectangle(50, 100, Color.DARKTURQUOISE));
        return layout;
    }
    /**
     * 设置顶部
     * @param layout 传入布局
     */
    public void settop(BorderPane layout){
        HBox hbox = new HBox();
        hbox.setPadding(new Insets(15, 12, 15, 12));
        hbox.setSpacing(10);
        hbox.setStyle("-fx-background-color: #336699");
        Label toplabel = new Label("XXXX科技有限公司");
        toplabel.setFont(new Font(35));
        toplabel.setTextFill(Color.BLACK);
        hbox.getChildren().add(toplabel);
        
        VBox vbox = new VBox();
        Separator sper = new Separator();
        sper.setOrientation(Orientation.HORIZONTAL);
        sper.setStyle(" -fx-background-color: #e79423;-fx-background-radius: 2;");
        vbox.getChildren().addAll(hbox,sper);
        
        layout.setTop(vbox);
    }
    /**
     * 设置左边部分
     * @param layout 传入的布局
     */
    public void setleft(BorderPane layout){
        //第一个根节点
        VBox vb1 = new VBox(5);
        vb1.setPadding(new Insets(15, 12, 15, 12));
        tree1btn1.setText("支付密码器管理");
        tree1btn1.setPrefSize(150, 20);
        
        tree1btn2.setText("支付密码账户管理");
        tree1btn2.setPrefSize(150, 20);
        
        vb1.getChildren().addAll(tree1btn1,tree1btn2);
        TitledPane node1 = new TitledPane("支付密码器管理",vb1);
        
        //第二个根节点
        VBox vb2 = new VBox(5);
        vb2.setPadding(new Insets(15, 12, 15, 12));
        tree2btn1.setText("机构管理");
        tree2btn1.setPrefSize(150, 20);
        
        tree2btn2.setText("用户管理管理");
        tree2btn2.setPrefSize(150, 20);
        
        tree2btn3.setText("核验规则设置");
        tree2btn3.setPrefSize(150, 20);
        
        tree2btn4.setText("企业客户管理");
        tree2btn4.setPrefSize(150, 20);
        
        vb2.getChildren().addAll(tree2btn1,tree2btn2,tree2btn3,tree2btn4);
        TitledPane node2 = new TitledPane("系统管理",vb2);
        
        //第三个根节点
        VBox vb3 = new VBox(5);
        vb3.setPadding(new Insets(15, 12, 15, 12));
        tree3btn1.setText("票据核验");
        tree3btn1.setPrefSize(150, 20);
        
        tree3btn2.setText("密码器状态");
        tree3btn2.setPrefSize(150, 20);
        
        tree3btn3.setText("账户分布情况");
        tree3btn3.setPrefSize(150, 20);
        
        tree3btn4.setText("密码器中账户");
        tree3btn4.setPrefSize(150, 20);
        
        vb3.getChildren().addAll(tree3btn1,tree3btn2,tree3btn3,tree3btn4);
        TitledPane node3 = new TitledPane("工具",vb3);
        
        //第四个根节点
        VBox vb4 = new VBox(5);
        vb4.setPadding(new Insets(15, 12, 15, 12));
        tree4btn1.setText("用户日志");
        tree4btn1.setPrefSize(150, 20);
        
        tree4btn2.setText("密码器日志");
        tree4btn2.setPrefSize(150, 20);
        
        tree4btn3.setText("票据日志");
        tree4btn3.setPrefSize(150, 20);
        
        tree4btn4.setText("账号签约明细");
        tree4btn4.setPrefSize(150, 20);
        
        tree4btn5.setText("密码器发行情况明细");
        tree4btn5.setPrefSize(150, 20);
        
        vb4.getChildren().addAll(tree4btn1,tree4btn2,tree4btn3,tree4btn4,tree4btn5);
        TitledPane node4 = new TitledPane("报表与日志管理",vb4);
        
        
        //设置树形根节点
        Accordion accordion = new Accordion();
        accordion.getPanes().add(node1);
        accordion.getPanes().add(node2);
        accordion.getPanes().add(node3);
        accordion.getPanes().add(node4);
        
        HBox hb = new HBox();
        Separator sper = new Separator();
        sper.setOrientation(Orientation.VERTICAL);
        sper.setStyle(" -fx-background-color: #e79423;-fx-background-radius: 2;");
        hb.getChildren().addAll(accordion,sper);
        
        //将树形节点加如布局的左边
        layout.setLeft(hb);
        
        
    }
    /**
     * 设置中间部分
     * @param layout 传入的布局 
     */
    public void setcenter(final BorderPane layout){
    Label testt = new Label("默认页面");
    layout.setCenter(testt);
    //树节点1的第一个按钮功能页面的设置
    tree1btn1.setOnAction(new EventHandler() {
        @Override
        public void handle(ActionEvent t) {
            layout.setCenter(settree1btn1centerlayout(JsonMethod.getList()));
        }
    });
    //树节点1的第二个按钮功能页面的设置
    tree1btn2.setOnAction(new EventHandler() {
        @Override
        public void handle(ActionEvent t) {
            layout.setCenter(settree1btn2centerlayout());
        }
    });
    }
    /**
     * 树节点1的第一个按钮的页面设置
     * @return 返回一个竖直方向的布局
     */
    public VBox settree1btn1centerlayout(final ObservableList list){
        //最上面一排按钮
        HBox tophb = new HBox(5);
        tophb.setPadding(new Insets(15, 12, 15, 12));
        Button btn1 = new Button("发行");
        btn1.setPrefSize(60, 20);
        Button btn2 = new Button("解锁");
        btn2.setPrefSize(60, 20);
        Button btn3 = new Button("停用");
        btn3.setPrefSize(60, 20);
        Button btn4 = new Button("启用");
        btn4.setPrefSize(60, 20);
        Button btn5 = new Button("挂失");
        btn5.setPrefSize(60, 20);
        tophb.getChildren().addAll(btn1,btn2,btn3,btn4,btn5);
        
        //中间一行
        VBox centervb = new VBox(5);
        centervb.setPadding(new Insets(15, 12, 5, 12));
        Label labelct = new Label("查询条件");  //外面标题
        labelct.setFont(new Font(15));
        HBox center_hb = new HBox(5);
        center_hb.setPadding(new Insets(5, 12, 15, 0));
        Label label1 = new Label("密码器编号");
        Label label2 = new Label("密码器账户");
        Label label3 = new Label("客户号");
        TextField tf1= new TextField();
        tf1.setPrefColumnCount(10);  //设置偏爱的文本框宽度
        TextField tf2= new TextField();
        tf2.setPrefColumnCount(10);  //设置偏爱的文本框宽度
        TextField tf3= new TextField();
        tf3.setPrefColumnCount(10);  //设置偏爱的文本框宽度
        Button btnquery = new Button("查询");
        btnquery.setPrefSize(60, 20);
        center_hb.getChildren().addAll(label1,tf1,label2,tf2,label3,tf3,btnquery);
        centervb.getChildren().addAll(labelct,center_hb);
        
        //下面表格
        
        TableView tableview = new TableView<>();
        TableColumn clo1 = new TableColumn();
        clo1.setText("密码器编号");
        clo1.setCellValueFactory(new PropertyValueFactory("MMQBH"));
        clo1.setMinWidth(100);
//        tableview.getColumns().add(clo1);
        TableColumn clo2 = new TableColumn();
        clo2.setText("生产厂商");
        clo2.setCellValueFactory(new PropertyValueFactory("SCCS"));
        clo2.setMinWidth(100);
//        tableview.getColumns().add(clo2);
        TableColumn clo3 = new TableColumn();
        clo3.setText("密码器状态");
        clo3.setCellValueFactory(new PropertyValueFactory("ZT"));
        clo3.setMinWidth(100);
//        tableview.getColumns().add(clo3);
        TableColumn clo4 = new TableColumn();
        clo4.setText("客户号");
        clo4.setCellValueFactory(new PropertyValueFactory("KHH"));
        clo4.setMinWidth(100);
//        tableview.getColumns().add(clo4);
        TableColumn clo5 = new TableColumn();
        clo5.setText("客户名称");
        clo5.setCellValueFactory(new PropertyValueFactory("KHMC"));
        clo5.setMinWidth(100);
//        tableview.getColumns().add(clo5);
        TableColumn clo6 = new TableColumn();
        clo6.setText("是否本行发行");
        clo6.setCellValueFactory(new PropertyValueFactory("BHFX"));
        clo6.setMinWidth(100);
//        tableview.getColumns().add(clo6);
        TableColumn clo7 = new TableColumn();
        clo7.setText("发行/登记日期");
        clo7.setCellValueFactory(new PropertyValueFactory("FXRQ"));
        clo7.setMinWidth(100);
//        tableview.getColumns().add(clo7);
        TableColumn clo8 = new TableColumn();
        clo8.setText("创建人");
        clo8.setCellValueFactory(new PropertyValueFactory("CJR"));
        clo8.setMinWidth(100);
//        tableview.getColumns().add(clo8);
        tableview.setItems(list);
        tableview.getColumns().addAll(clo1,clo2,clo3,clo4,clo5,clo6,clo7,clo8);
//        tableview.setEditable(true);
        VBox tavbox = new VBox();
        tavbox.setSpacing(5);
        tavbox.setPadding(new Insets(10, 0, 0, 10));
        tavbox.getChildren().addAll(tableview);
        
        //添加一行table的功能
        final TextField tx1 = new TextField();
        tx1.setPromptText("密码器编号");
        tx1.setMaxWidth(clo1.getPrefWidth());
        final TextField tx2 = new TextField();
        tx2.setPromptText("生产厂商");
        tx2.setMaxWidth(clo2.getPrefWidth());
        final TextField tx3 = new TextField();
        tx3.setPromptText("密码器状态");
        tx3.setMaxWidth(clo3.getPrefWidth());
        final TextField tx4 = new TextField();
        tx4.setPromptText("客户号");
        tx4.setMaxWidth(clo4.getPrefWidth());
        final TextField tx5 = new TextField();
        tx5.setPromptText("客户名称");
        tx5.setMaxWidth(clo5.getPrefWidth());        
        final TextField tx6 = new TextField();
        tx6.setPromptText("是否本行发行");
        tx6.setMaxWidth(clo6.getPrefWidth());        
        final TextField tx7 = new TextField();
        tx7.setPromptText("发行/登记日期");
        tx7.setMaxWidth(clo7.getPrefWidth());
        final TextField tx8 = new TextField();
        tx8.setPromptText("创建人");
        tx8.setMaxWidth(clo8.getPrefWidth());
        
        final Button addButton = new Button("添加记录");
        addButton.setPrefSize(100, 20);
        addButton.setOnAction(new EventHandler() {
            @Override
            public void handle(ActionEvent e) {
                list.add(new Message(
                        tx1.getText(),
                        tx2.getText(),
                        tx3.getText(),
                        Integer.parseInt(tx4.getText()),
                        tx5.getText(),
                        tx6.getText(),
                        tx7.getText(),
                        tx8.getText()));
                tx1.clear();
                tx2.clear();
                tx3.clear();
                tx4.clear();
                tx5.clear();
                tx6.clear();
                tx7.clear();
                tx8.clear(); 
            }
        });
        HBox addbox = new HBox(10);
        addbox.setPadding(new Insets(10, 10, 10, 10));
        addbox.getChildren().addAll(tx1,tx2,tx3,tx4,tx5,tx6,tx7,tx8,addButton);
        
        
        
        //分割线
        Separator sper1 = new Separator();
        sper1.setOrientation(Orientation.HORIZONTAL);
        Separator sper2 = new Separator();
        sper2.setOrientation(Orientation.HORIZONTAL);
        
        VBox vblast = new VBox();
        vblast.getChildren().addAll(tophb,sper1,centervb,sper2,tavbox,addbox);
        return vblast;
    }
        /**
     * 树节点1的第二个按钮的页面设置
     * @return 返回一个竖直方向的布局
     */
    public VBox settree1btn2centerlayout(){
        VBox vblast = new VBox();
        Label test = new Label("支付密码账户管理器的页面");
        vblast.getChildren().addAll(test);
        vblast.setStyle("-fx-background-color: #221489");
        return vblast;
    }
    @Override
    public void start(Stage primaryStage) {
        BorderPane root = setBorder();
        settop(root);
        setleft(root);
        setcenter(root);
        Scene scene = new Scene(root,1000,600);
        primaryStage.setTitle("Layout sample");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

public static void main(String[] args) {
        launch(args);
    }
}
上面有一个table的数据绑定知识点。。。。

你可能感兴趣的:(javafx)