Java 添加(新标签(value.substring(lastPartIndex)); } } 设置图形(hbox); } } }; 返回单元; } }; } 我喜欢你最后的建议。我喜欢你最后的建议。 public Callback<TableColumn&
添加(新标签(value.substring(lastPartIndex)); } } 设置图形(hbox); } } }; 返回单元; } }; }Java 添加(新标签(value.substring(lastPartIndex)); } } 设置图形(hbox); } } }; 返回单元; } }; } 我喜欢你最后的建议。我喜欢你最后的建议。 public Callback<TableColumn&,java,javafx-2,Java,Javafx 2,添加(新标签(value.substring(lastPartIndex)); } } 设置图形(hbox); } } }; 返回单元; } }; } 我喜欢你最后的建议。我喜欢你最后的建议。 public Callback<TableColumn<Address, String>, TableCell<Address, String>> getCellFactory() { return new Callback<TableColumn
我喜欢你最后的建议。我喜欢你最后的建议。
public Callback<TableColumn<Address, String>, TableCell<Address, String>> getCellFactory() {
return new Callback<TableColumn<Address, String>, TableCell<Address, String>>() {
@Override
public TableCell<Address, String> call( final TableColumn<Address, String> param ) {
final TableCell<Address, String> cell = new TableCell<Address, String>() {
@Override
protected void updateItem( final String value, final boolean empty ) {
setGraphic( null );
if( null != getTableRow() && !empty ) {
final HBox hbox = new HBox();
hbox.setAlignment( Pos.CENTER_LEFT );
hbox.getChildren().clear();
if( null == value ) {
return;
}
final int index = value.toLowerCase().indexOf(str);
if( -1 == index ) {
//no match
hbox.getChildren().add( new Label( value ) );
} else {
//part of string before match
hbox.getChildren().add( new Label( value.substring( 0, index ) ) );
//matched part
final Label label = new Label( value.substring( index, index + str.length() ) );
label.setStyle( "-fx-background-color: #FFFFBF;-fx-text-fill: #FF0000;" );
hbox.getChildren().add( label );
//part of string after match
final int lastPartIndex = index + str.length();
if( lastPartIndex < value.length() ) {
hbox.getChildren().add( new Label( value.substring( lastPartIndex ) ) );
}
}
setGraphic( hbox );
}
}
};
return cell;
}
};
}