By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,180 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

can not load some images to display in a JLabel??

P: n/a
Hi,
I am getting this weird behavior. I have couple of gif and jpg files
that I would like to display in JLabel. It displays one jpg image but
it does not display other gifs and jpgs. Any idea why it would do so.
Sample code is :

JPanel logoPanel = new JPanel();
logoPanel.setLayout(new BoxLayout(logoPanel, BoxLayout.X_AXIS));

ImageIcon logo = new ImageIcon(_imageFileName);
JLabel iconLabel; //label containing logo
iconLabel = new JLabel( logo, SwingConstants.LEFT);
logoPanel.add(iconLabel);

Any suggestions and ideas. In case you are wondering, I also tried
using explicit MediaTracker to make sure image gets loaded although
constructor for ImageIcon loads image using MediaTracker. Thanks.

Prabhat
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Prabhat,
I solved a similar problem with JTree's using the form:

.... new ImageIcon(getClass().getResource("/coins1.gif"))

HTH

Jim

prabhat wrote:

Hi,
I am getting this weird behavior. I have couple of gif and jpg files
that I would like to display in JLabel. It displays one jpg image but
it does not display other gifs and jpgs. Any idea why it would do so.
Sample code is :

JPanel logoPanel = new JPanel();
logoPanel.setLayout(new BoxLayout(logoPanel, BoxLayout.X_AXIS));

ImageIcon logo = new ImageIcon(_imageFileName);
JLabel iconLabel; //label containing logo
iconLabel = new JLabel( logo, SwingConstants.LEFT);
logoPanel.add(iconLabel);

Any suggestions and ideas. In case you are wondering, I also tried
using explicit MediaTracker to make sure image gets loaded although
constructor for ImageIcon loads image using MediaTracker. Thanks.

Prabhat


--
! Jim Katz
! NetBeans 3.5.1
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.