1

I have a very big image but I want to resize it inside jLabel in Netbeans using jLabel properties. Please help me if possible.

Vipul Kumar
  • 67
  • 3
  • 11
  • For [example](http://stackoverflow.com/questions/22679717/resizing-image-to-fit-in-jlabel/22680573#22680573), [example](http://stackoverflow.com/questions/18010803/java-swing-resize-imageicon-according-to-jlabel/18011430#18011430), [example](http://stackoverflow.com/questions/18351186/resizing-jlabel-imageicon-with-html/18352000#18352000), [example](http://stackoverflow.com/questions/11698271/how-to-make-jlabel-with-image-fill-borderlayout-center/11698479#11698479). The short answer is, you'll need to get your hands dirty – MadProgrammer Oct 20 '15 at 04:23

1 Answers1

1

You can use the Image.getScaledInstance(...) method to scale the image to your desired size.

Then you create an ImageIcon using the image and add the Icon to the JLabel.

Edit:

You can also try using Darryl's Stretch Icon. Using this class the Icon will resize dynamically as frame resizes if you use an appropriate layout manager.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Can you give an example? – Vipul Kumar Oct 20 '15 at 04:23
  • @VipulKumar For [example](http://stackoverflow.com/questions/22679717/resizing-image-to-fit-in-jlabel/22680573#22680573), [example](http://stackoverflow.com/questions/18010803/java-swing-resize-imageicon-according-to-jlabel/18011430#18011430), [example](http://stackoverflow.com/questions/18351186/resizing-jlabel-imageicon-with-html/18352000#18352000), [example](http://stackoverflow.com/questions/11698271/how-to-make-jlabel-with-image-fill-borderlayout-center/11698479#11698479). The short answer is, you'll need to get your hands dirty – MadProgrammer Oct 20 '15 at 04:23
  • @Camickr Where's the link to your resizable icon? – MadProgrammer Oct 20 '15 at 04:25
  • Also [The Perils of Image.getScaledInstance()](https://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html) – MadProgrammer Oct 20 '15 at 04:28
  • @VipulKumar, `Can you give an example?` - I gave you the class and method to use. You can read the API to see what the paramters are. You can also search the forum or web yourself for examples. You can't program if you don't learn to use the API and the resources of the web yourself. Don't rely on other to read the API for you. – camickr Oct 20 '15 at 04:28
  • I am a beginner. So how can I do this in an easy way? Remember, I am using Netbeans. – Vipul Kumar Oct 20 '15 at 04:29
  • It doesn't matter whether you are a beginner, you still need to learn how to read the API. What part about the API do you not understand?. I have never used an IDE like Netbeans so I don't know how you do this. Learn how to write code without depending on the IDE then you learn how to use Java and not the IDE. – camickr Oct 20 '15 at 04:33
  • @VipulKumar there so many tutorials are there . Check it . So you can also get some idea and you may become expert. Try your self. – user5840896 Jan 30 '17 at 06:24