Forums Register Login

Picture not appearing

+Pie Number of slices to send: Send
Hi all,
Would anybody please tell me what might be wrong with the following lines of code:
import java.awt.*;
import javax.swing.*;
public class Test extends JFrame{
private String name = "image.gif";
private Icon icon = new ImageIcon(name);
private JLabel label;
public Test(){
Container c = getContentPane();
c.setLayout( new FlowLayout() );
label = new JLabel(icon);
c.add(label);
setSize(800,600);
setVisible(true);
}
public static void main (String args[]) {
Test t = new Test(); t.setDefaultCloseOperationJFrame.EXIT_ON_CLOSE);
}
NOTE: the image is in the same directory of the java and class files.
This code should just show my picture, right?? then what might be wrong ??
+Pie Number of slices to send: Send
Ar yes
Ola gharably
Please try to change your code to the following
private ImageIcon icon;
label.setIcon(icon=new ImageIcon("image.gif"));
Hope to solve your problem
+Pie Number of slices to send: Send
Thank you alot Siu, i've tried your suggestion but unfortunatly it didn't solve my problem :roll:
I'm still with my problem
+Pie Number of slices to send: Send
Nope... it should work just the way you have it. Try and load a different image. It may be a problem with the GIF.
+Pie Number of slices to send: Send
I'm still with my problem
Get damage!!I do not know why it does not work~~~~
please try to delete
c.setLayout( new FlowLayout() );
change to
label.setBounds(100,100,icon.getIconWidth(),icon.getIconHeight());
:roll:
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1008 times.
Similar Threads
Picture Woes
I can't load a file with getResource
Selecting applications using Icons in Swing
How to checked CheckBox in JTree only when user click on CheckBox?
running gifs
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:24:05.