最近boss要求寫一個桌面客戶端程序,其中需要以列表形式顯示圖片,現記錄下如何通過JavaFX實現
ListView<Object> contentlist;
List<Object> contentLabelList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
contentLabelList.add(sdf.format(new Date(System.currentTimeMillis())) + ":");
ImageView imageView = new ImageView();
Image image = new Image("file:C://chat/1.gif");
imageView.setImage(image);
contentLabelList.add(imageView);
ObservableList<Object> strList = FXCollections.observableArrayList(contentLabelList);
contentlist.setItems(strList);
實現效果:
更多Java開發可以關注本人微信公衆號查看