Java GUI頁面顯示圖片大小

在頁面想要顯示圖片,可以使用ImageIcon標籤組件獲取圖片,然後將圖片添加到JLable標籤組件顯示出,以及想要顯示不同大小的圖片,自適應容器大小顯示圖片。

1.正常顯示圖片

ImageIcon imageic = new ImageIcon("*.jpg");
JLabel lable = new JLabel(imageic);

2.自定義顯示圖片大小

ImageIcon imageic = new ImageIcon("*.jpg");
imageic.setImage(imageic.getImage().getScaledInstance(200, 300,Image.SCALE_DEFAULT));
JLabel lable = new JLabel(imageic);

3.自適應容器大小

Image image = new Image("**.jpg");
JLabel lable = new JLabel();
lable.setIcon(SwingUtil.createAutoIcon(image, true));

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章