javafx tableview 示例

javafx tableview 示例


 public void initTableBox(TableView listBox) {
        listBox.setEditable(true);
        listBox.getColumns().clear();
        TableColumn Column01 = new TableColumn("");
        Column01.setMinWidth(260);
        Column01.setCellValueFactory(new PropertyValueFactory("col01"));
        Column01.setCellFactory(new Callback, TableCell>() {  
            public TableCell call(TableColumn param) {  
                return new TableCell() {  
                    ObservableValue ov;  
                    @Override  
                    public void updateItem(String item, boolean empty) {  
                        super.updateItem(item, empty);  
                        if (!isEmpty()) {  
                            ov = getTableColumn().getCellObservableValue(getIndex());  
                            if(getTableRow() != null && !ov.equals("") && !item.equals("") && item.substring(0,1).equals("*")){  
                                this.getTableRow().setStyle("-fx-background-color:#99ffff;-fx-font-weight:bold;");
                            }else if(getTableRow() != null && !ov.equals("") && !item.equals("") && item.contains(":")){
                                this.getTableRow().setStyle("-fx-font-weight:bold;");
                            }else{
                                this.getTableRow().setStyle("");
                            }
                        }  
                        setText(item);  
                    }  
                };  
            }  
        });  
 
        //
        TableColumn Column02 = new TableColumn("");
        Column02.setMinWidth(100);
        Column02.setCellValueFactory(new PropertyValueFactory("col02"));
        //
        TableColumn Column03 = new TableColumn("");
        Column03.setMinWidth(100);
        Column03.setCellValueFactory(new PropertyValueFactory("col03"));
        //
        TableColumn Column04 = new TableColumn("");
        Column03.setMinWidth(120);
        Column04.setCellValueFactory(new PropertyValueFactory("col04"));
        listBox.getColumns().addAll(Column01,Column02, Column03, Column04);
    }

你可能感兴趣的:(javafx)