Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying Graphic Buttons on a Toolbar

 
C Lindstrom
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic