• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Image doesnt shows propely in java swing

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,
I am trying too make small app that takes pics from directory and show images on JLabel when user click on next button.but i dont know why it doesn't work properly.actually when i click on Next it show image but i need to resize frame every time.Please look on that and let me know where i am wrong. sorry for silly English ;)


 
Rancher
Posts: 3204
29
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default components have a size of (0, 0). So when you add a component to a frame there is nothing to paint. In order to give a component a size you need to invoke the layout manager. When you resize a frame the layout manager is automatically invoked so your component is give a size and location.

You can manually invoke the layout manager by using code like:



However, a better approach is the add the label to the GUI when you create the GUI. Then when you want to change the image of the label you just use:

label.setIcon( .... );

Now the label will invoke the layout manager automatically and the label will repaint itself.
 
Rob Camick
Rancher
Posts: 3204
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crossposted: http://stackoverflow.com/questions/30817036/image-doesnt-shows-on-jlabel-when-click-on-next-button-using-java-swing

Quit cross posting. Its annoying to spend the time answering a question only to find out the exact same answer has already been given and you didn't bother to reply stating an answer has been found.
 
parampreet Singh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks buddy,your solution works. about cross posting?, i will take care next time!
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic