🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages Started by Bodhi Tue, 19 Jul 2005 10:59
Button/Icon problem
#491
Author: Bodhi
Date: Tue, 19 Jul 2005 10:59
57 lines
2349 bytes
Hi,



I've been trying to solve my problem for days now, but with no luck. I'm new
to Swing programming, but as far as I can tell, my code should be ok. (See
below).



The problem is that I'm trying to create a button with an icon, but every
time I end up with a button without an icon. I've added the image in the
project view (it's also physically located in the same directory as the java
file) and double clicking the icon name shows the image in JBuilder. So as
far as I understand, there should not be a "path" or location problem.



Running the getImageLoadStatus() method returns a code 4, which to my
understanding indicates a loading problem.



If anyone can give me a clue of how to solve my problem, it would be greatly
appreciated.



Sincerely,

B.


package icons;

import javax.swing.*;

 public class Icons extends JFrame {
     ImageIcon icon = new ImageIcon("3dman.gif");
     JButton button = new JButton(icon);
     JPanel pane = new JPanel();

     public Icons() {
       setSize(400, 300);
       setTitle("Icon Test Frame");
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       //System.out.println(icon.getImageLoadStatus());
       pane.add(button);
       setContentPane(pane);
       show();
     }

     public static void main(String[] arguments) {
         Icons ike = new Icons();

     }
 }
Re: Button/Icon problem
#493
Author: Lori M Olson [TeamB]
Date: Tue, 19 Jul 2005 14:34
89 lines
3266 bytes
Bodhi wrote:
> Hi,
> 
> 
> 
> I've been trying to solve my problem for days now, but with no luck. I'm new
> to Swing programming, but as far as I can tell, my code should be ok. (See
> below).
> 
> 
> 
> The problem is that I'm trying to create a button with an icon, but every
> time I end up with a button without an icon. I've added the image in the
> project view (it's also physically located in the same directory as the java
> file) and double clicking the icon name shows the image in JBuilder. So as
> far as I understand, there should not be a "path" or location problem.
> 
> 
> 
> Running the getImageLoadStatus() method returns a code 4, which to my
> understanding indicates a loading problem.
> 
> 
> 
> If anyone can give me a clue of how to solve my problem, it would be greatly
> appreciated.
> 
> 
> 
> Sincerely,
> 
> B.
> 
> 
> package icons;
> 
> import javax.swing.*;
> 
>  public class Icons extends JFrame {
>      ImageIcon icon = new ImageIcon("3dman.gif");
>      JButton button = new JButton(icon);
>      JPanel pane = new JPanel();
> 
>      public Icons() {
>        setSize(400, 300);
>        setTitle("Icon Test Frame");
>        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>        //System.out.println(icon.getImageLoadStatus());
>        pane.add(button);
>        setContentPane(pane);
>        show();
>      }
> 
>      public static void main(String[] arguments) {
>          Icons ike = new Icons();
> 
>      }
>  }
> 
> 

It can't find the file "3dman.gif".  You need to understand how it would 
find that file, if you are going to load it that way.

I prefer loading images as resources, and then making sure they are in 
the classpath.

The Java Tutorial covers this topic well:

http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html

-- 

Regards,

Lori Olson [TeamB]

------------

Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.

Google Advanced Newsgroup Search
     http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
     http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
     http://www.visi.com/~gyles19/fom-serve/cache/1.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads