473,386 Members | 1,924 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,386 software developers and data experts.

Need help, ImageIcon on the Label

crystal2005
Hi all,

Can anyone tell me why my image doesn't appear in my frame's container? When I change imageIcon to just normal Label, it does go work.

In another condition, if i don't use method return (what is it called? emm...). ImageIcon does work on my normal Label.

Expand|Select|Wrap|Line Numbers
  1. package practise;
  2.  
  3. import java.awt.*;
  4. import javax.swing.*;
  5.  
  6. public class layout_test {
  7.  
  8.     public Container createContentPane() {
  9.         JPanel contentPane = new JPanel(new BorderLayout());
  10.         contentPane.setOpaque(true);
  11.  
  12.         contentPane.add(createNorthPanel(), BorderLayout.NORTH);
  13.         contentPane.add(createCenterPanel(), BorderLayout.CENTER);
  14.  
  15.         return contentPane;
  16.     }
  17.  
  18.     public JPanel createCenterPanel() {
  19.         JPanel centerPanel = new JPanel();
  20.         JLabel image = new JLabel(new ImageIcon("Bovinetine.jpg")); // Image doesn't appear
  21.         centerPanel.add(image);
  22.         return centerPanel;
  23.     }
  24.  
  25.     public JPanel createNorthPanel() {
  26.         JPanel northPanel = new JPanel(new GridLayout(1,3));
  27.         JButton b1 = new JButton("b1"), b2 = new JButton("b2"), b3 = new JButton("b3");
  28.         northPanel.add(b1);
  29.         northPanel.add(b2);
  30.         northPanel.add(b3);
  31.         return northPanel;
  32.     }
  33.  
  34.     public static void main(String[] args) {
  35.         JFrame frame = new JFrame("Testing Layout with Image");
  36.         layout_test layout = new layout_test();
  37.         frame.setContentPane(layout.createContentPane());
  38.         frame.pack();
  39.         frame.setVisible(true);
  40.     }
  41.  
  42. }
  43.  
Thanks for any advice...
May 27 '08 #1
1 1879
BigDaddyLH
1,216 Expert 1GB
The most common reason for an image not appearing is that it doesn't exist, you misspelled the filename or the file is in the wrong place.
May 27 '08 #2

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

Similar topics

1
by: AIK | last post by:
Can someone show me or point me to a nice tutorial on showing imageicon images in a jframe? Thanks.
0
by: Mik | last post by:
I have a problem with drawing ImageIcon objects on a JPanel in a JApplet Everything is ok when I run applet locally, but when it's run from a server the images are not showing ImageIcon objects...
14
by: ra7l | last post by:
hi all bleas h need help in cods GUI and Thread i need help function start () run() white () join () sleep ()
5
by: ra7l | last post by:
Hi All .. First Thanks to All For Help Me .. ok ..This Code it Move Train but one errore small.. Where Correct Cods Thanks All .. :)
0
nomad
by: nomad | last post by:
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...
20
by: fatfatpopo | last post by:
Anyone who understand the codes below, can you please kindly explain to me by adding comments.. thanks in advance // <applet code="ImageSlider" width="400" height="400"></applet> import...
1
by: twin2003 | last post by:
need help with inventory part 5 here is what I have to do Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next...
1
by: Kburge03 | last post by:
Hi!! I've been working on this assingment for class where I have to design and implement an application that displays two Die objects, a button, and a label. Every time the button is pushed, the...
1
by: moizpalitanawala | last post by:
Hello Friends The code below has no error at compile time. But while executing, it does not show the icon at the left hand top corner of the frame, where a java cup icon is originally shown. I...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.