473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with GUI and applying images

nomad
664 Expert 512MB
I made a simple GUI program in which I want to place a .gif into a button.
I did this but the .gif does not show up. The load.gif is in the same package (chapter 10) as the project.
If I take these files to a default package it will work. So I know there must be a way to call the gif (ie make a dir to find the image)
Can someone help please

[size=2]Here is my code[/size]
[size=2][/size]
Expand|Select|Wrap|Line Numbers
  1.  package chapter10; 
  2.  
  3.  
  4.  
  5. import java.awt.BorderLayout;
  6.  
  7.  
  8.  
  9. import javax.swing.ImageIcon;
  10.  
  11. import javax.swing.JButton;
  12.  
  13. import javax.swing.JFrame;
  14.  
  15. import javax.swing.JScrollPane;
  16.  
  17. import javax.swing.JTextArea;
  18.  
  19. import javax.swing.JToolBar;
  20.  
  21.  
  22.  
  23. public class FeedBar2 extends JFrame {
  24.  
  25.  
  26.  
  27. public FeedBar2() {
  28.  
  29. super("FeedBar 2");
  30.  
  31. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  32.  
  33. // create icons
  34.  
  35. ImageIcon loadIcon = new ImageIcon("load.gif");
  36.  
  37.  
  38.  
  39. // create buttons
  40.  
  41. JButton load = new JButton("Load", loadIcon);
  42.  
  43.  
  44.  
  45. // add buttons to toolbar
  46.  
  47. JToolBar bar = new JToolBar();
  48.  
  49. bar.add(load);
  50.  
  51.  
  52.  
  53.  
  54.  
  55. // prepare user interface
  56.  
  57. JTextArea edit = new JTextArea(8, 40);
  58.  
  59. JScrollPane scroll = new JScrollPane(edit);
  60.  
  61. BorderLayout bord = new BorderLayout();
  62.  
  63. setLayout(bord);
  64.  
  65. add("North", bar);
  66.  
  67. add("Center", scroll);
  68.  
  69.  
  70.  
  71. pack();
  72.  
  73. setVisible(true);
  74.  
  75. }
  76.  
  77.  
  78.  
  79. public static void main(String[] arguments) {
  80.  
  81. FeedBar2 frame = new FeedBar2();
  82.  
  83. }
  84.  
Expand|Select|Wrap|Line Numbers
  1. }
  2.  
  3.  

[size=2]
[/size]nomad
Jun 5 '07 #1
0 1075

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: philjhanna | last post by:
Hi I'm having a problem applying return false to a div via addEventListener. I'm adding this so that I can drag (click-hold-move) over an image. (Its so that I can add zooming to the image)...
9
by: Daz | last post by:
Hello hello! I'm trying to finish off putting my design into HTML and I've come across a problem that I can't get my head around. I've got divs floating in two columns, but I'm having problems...
2
by: Tim Joyner | last post by:
I am using the EnableVisualStyle command to apply visual style to my program. After using this command and starting the main form, the images that I have assigned to controls such as the toolbar...
0
by: Jack Wu | last post by:
Hi I've spent a good majority of my day trying to figure out how to have PIL 1.1.5 working on my OSX 10.3.9_PPC machine. I'm still stuck and I have not gotten anywhere. Could somebody please...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.