473,287 Members | 1,395 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,287 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 1873
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: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.