2015-10-20 85 views
1

我有一個非常大的圖像,但我想在jabel中使用jLabel屬性在jLabel中調整它。如果可能,請幫助我。如何在JAVA Netbeans中調整jLabel中的圖片大小?

+0

對於[示例](http://stackoverflow.com/questions/22679717/resizing-image-to-fit-in-jlabel/22680573#22680573),[示例](http://stackoverflow.com/questions/18010803/java-swing-resize-imageicon -with-to-jlabel/18011430#18011430),[example](http://stackoverflow.com/questions/18351186/resizing-jlabel-imageicon-with-html/18352000# 18352000),[示例](http://stackoverflow.com/questions/11698271/how-to-make-jlabel-with-image-fill-borderlayout-center/11698479#11698479)。簡短的回答是,你需要把你的手弄髒 – MadProgrammer

回答

1

您可以使用Image.getScaledInstance(...)方法將圖像縮放到所需的大小。

然後,您使用圖像創建ImageIcon,並將圖標添加到JLabel

編輯:

您也可以嘗試使用達里爾的Stretch Icon。如果您使用適當的佈局管理器,則使用此類將在框架大小調整時動態調整圖標大小。

+0

你能舉個例子嗎? –

+0

@VipulKumar對於[示例](http://stackoverflow.com/questions/22679717/resizing-image-to-fit-in-jlabel/22680573#22680573),[示例](http://stackoverflow.com/questions/18010803/java-swing-resize-imageicon -with-to-jlabel/18011430#18011430),[example](http://stackoverflow.com/questions/18351186/resizing-jlabel-imageicon-with-html/18352000# 18352000),[示例](http://stackoverflow.com/questions/11698271/how-to-make-jlabel-with-image-fill-borderlayout-center/11698479#11698479)。簡短的回答是,你需要把你的手弄髒 – MadProgrammer

+0

@Camickr你的可調整大小的圖標的鏈接在哪裏? – MadProgrammer