• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Image doesnt shows propely in java swing

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3244
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3244
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks buddy,your solution works. about cross posting?, i will take care next time!
 
eat bricks! HA! And here's another one! And a tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic