[英]how to change the float value to rating stars (rating of jfoenix ) representation in tableView columns?
我正在嘗試更改我的 tableView 評級列的表示(請看圖 1)
進入 jfoenix 庫的評級明星以獲得更好的代表性
這是我的表格視圖的代碼(在控制器中):
@FXML
public void initialize(URL url, ResourceBundle rb) {
nom_client.setCellValueFactory(new PropertyValueFactory<Review, String>("nom_client_review"));
date_review.setCellValueFactory(new PropertyValueFactory<Review, String>("date_review"));
descrip_review.setCellValueFactory(new PropertyValueFactory<Review, String>("description_review"));
rating.setCellValueFactory(new PropertyValueFactory<Review, Float>("rating"));
try {
ObservableList<Review> reviewlist = ReviewCrud.getAllRecords();
populateTable(reviewlist);
} catch (ClassNotFoundException ex) {
Logger.getLogger(AfficherReview2Controller.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(AfficherReview2Controller.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void populateTable(ObservableList<Review> reviewlist) {
reviewtable.setItems(reviewlist);
}
請注意,我不允許使用 simplefloatproperty,這就是為什么我在評論class 中的評分設置為浮動
在我用來從我的數據庫中獲取數據的代碼下方:
public static ObservableList<Review> getAllRecords() throws ClassNotFoundException, SQLException {
Connection cnnx = ReviewConnection.getInstance().getCnx();
String requete = "SELECT * FROM review_client ";
try {
Statement st = cnnx.createStatement();
ResultSet rs = st.executeQuery(requete);
ObservableList<Review> reviewList = getReviewObjects(rs);
return reviewList;
} catch (SQLException ex) {
System.err.println(ex.getMessage());
throw ex;
}
}
private static ObservableList<Review> getReviewObjects(ResultSet rs) throws ClassNotFoundException, SQLException {
try {
ObservableList<Review> reviewList = FXCollections.observableArrayList();
while (rs.next()) {
Review r = new Review();
r.setNom_client_review(rs.getString("nom_client_review"));
r.setDate_review(rs.getString("date_review"));
r.setDescription_review(rs.getString("description_review"));
r.setRating(rs.getFloat("rating"));
reviewList.add(r);
}
return reviewList;
} catch (SQLException ex) {
System.err.println(ex.getMessage());
throw ex;
}
}
我唯一的目標是將評級列的浮點值轉換為 jfoenix 的星星
如果有人知道如何請幫助我
將不勝感激
你看過這個解決方案嗎: 使用 jQuery 和 CSS 將數字轉換為星級顯示
$.fn.stars = function() {
return $(this).each(function() {
// Get the value
var val = parseFloat($(this).html());
// Make sure that the value is in 0 - 5 range, multiply to get width
var size = Math.max(0, (Math.min(5, val))) * 16;
// Create stars holder
var $span = $('<span />').width(size);
// Replace the numerical value with stars
$(this).html($span);
});
}
此代碼在 jQuery 中,但您可以輕松遵循邏輯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.