• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying Graphic Buttons on a Toolbar

 
Greenhorn
Posts: 8
  • 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 load an iconed button onto a toolbar. If the graphic file does not exist, results are the same. To me, this implies I am not calling the .gif incorrectly. My best attempt is a very small button, no icon.
Checked the JavaRanch messages, and could not find one that addressed this issue. If you remember reading a solution to this, please reply with the link. Apparently no one else has had a problem with this. Is there some kind of plug-in I am missing
This is from day 21 of Cadenhead & Lemay�s Professional Edition of Teach Yourself Java 2, p. 536.
The code has been edited in the interest of brevity. Initially there were three buttons.


Thanks, Connie
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This works fine. Are you sure that the gif file is in the same directory as the java class? If the image file is not in the same directory as the java class, I get the very small box you described.
 
C Lindstrom
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thomas,
Thank you for verifying the code worked correctly. Fiddled around with it, and found the codet worked correctly when the graphics were called with an absolute path - �C:\foo\bar\graphic.jpg� rather than �graphic.jpg�. The next question is "how is the cwd determined?", but that is a question for another forum.
My apologies for nuisancing this forum with a non-swing inquiry.
Connie
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Connie, we have had several questions in several forums regarding loading images. A bunch were resolved by the solution you referred to: absolute path. Are you aware of any way to load an image file using relative paths? I haven't had a chance to search the API for this info, but if you come across an answer, please post it.
 
it's a teeny, tiny, wafer thin ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic