The Artima Developer Community
Sponsored Link

Java Answers Forum
what's the difference ?

3 replies on 1 page. Most recent reply: Jan 23, 2004 4:29 AM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
aj3423 aj

Posts: 16
Nickname: aj3423
Registered: Aug, 2003

what's the difference ? Posted: Jan 23, 2004 1:08 AM
Reply to this message Reply
Advertisement
i'd like to show a .jpg file in a label, but the follow code doesn't work, the label doesn't show the "1.jpg". then i tried another .jpg file(2.jpg), it works correctly...
the difference between the two .jpg file is:

"1.jpg" is a file that i created using mspaint.exe

"2.jpg" is a file downloaded from the internet

i dont know whats the difference. how could it be the matter? does it mean i cannot use the "jpg" created by myself?
(windows XP , jdk 1.42)
Thanks in advance !

// the code:

import java.awt.*;
import javax.swing.*;

class Test extends JFrame {

ImageIcon image = new ImageIcon("1.jpg");
JPanel p = new JPanel();
JLabel lbl = new JLabel();

public Test() {

super("test");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

lbl.setIcon(image);
p.add(lbl);
lbl.setBackground(Color.red);
getContentPane().add(p);

}

public static void main(String args[]) {
Test t = new Test();
t.show();
t.pack();
}
}


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: what's the difference ? Posted: Jan 23, 2004 1:47 AM
Reply to this message Reply
I tried ur programme by making a .jpg file by ms paint and it worked fine.

But here is thing i did next.

I tried creating an image from ms-paint. When i tried to save the file as jpg file I did not change the option in SaveTypeAs combo from Monochrome bit map(default option for mspaing ) to JPEG file interchange format. I just gave the name 1.jpg while the file type in the combo below was different.

And it didnt work.
Hope that may bring some idea in ur mind...what was wrong in the second step.

aj3423 aj

Posts: 16
Nickname: aj3423
Registered: Aug, 2003

Re: what's the difference ? Posted: Jan 23, 2004 3:56 AM
Reply to this message Reply
thank you mausam. i tried what you mean, save 3.jpg as Monochrome bit map(default option), but i failed again.
i don't know why it doesn't work with my jpg....

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: what's the difference ? Posted: Jan 23, 2004 4:29 AM
Reply to this message Reply
dont save it as monochrom gif.

Before saving ur jpg file use the option for jpeg in the save type as combo. It will work

Flat View: This topic has 3 replies on 1 page
Topic: JAVA DEVELOPERS Previous Topic   Next Topic Topic: AutevoSpaces - Worlds First SSI Clustered JavaSpaces

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use