Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to make a Graphics image pass across a .jpg Icon image using a JSlider

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am trying to make a Graphics image (arrow) pass across a .jpg image(Balloon). The Graphics image is controlled by a JSlider. If you run this program you can see how the Graphics image moves. I commented out the code at Lines 61-64 and 74 that is giving me problems making the underlying ImageIcon. This involves getting both Images the same Frame so that one can pass over the other. I would appreciate your assistance.

Fred

balloon.jpg
[Thumbnail for balloon.jpg]
 
Rancher
Posts: 3249
30
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way is to extend JLabel, instead of JPanel. Then you just use the image as the icon for the label and you customize the paintComponent() method to paint the arrow.

 
Fred Hutchins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JLabel was right on point. Thanks.

I started exploring other options with JLabel and found that you can also use the ImageIcon option within the paintComponent method and also specify the position of the icon.
Although it seems awkward having to right out the entire path.

 
Rob Camick
Rancher
Posts: 3249
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should NOT be reading the Icon in the paintComponent() method. This method will be called whenever the component need to repaint itself.

My suggestion to use a JLabel was to take advantage of the default behaviour of how a JLabel paints an Icon. If you are going to do custom painting for both images then you should not extend JLabel, but instead extend JPanel or JComponent.

 
Fred Hutchins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it. Thanks.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Fred Hutchins wrote:Although it seems awkward having to right out the entire path.


Loading Images Using getResource
 
Fred Hutchins
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. I should be able to work this into the code.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic