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

GUI (JLabel) .JPEG not recegnized

momotaro
357 100+
my code works fine with .GIF but not with .JPEG!!??
jdk.6.0_02
jre1.6.0_05
Jun 11 '08 #1
10 2240
BigDaddyLH
1,216 Expert 1GB
Please explain. Even better, provide a SSCCE: http://mindprod.com/jgloss/sscce.html
Jun 11 '08 #2
momotaro
357 100+
Please explain. Even better, provide a SSCCE: http://mindprod.com/jgloss/sscce.html
Expand|Select|Wrap|Line Numbers
  1. ort java.awt.BorderLayout;
  2. import javax.swing.ImageIcon;
  3. import javax.swing.JLabel;
  4. import javax.swing.JFrame;
  5.  
  6. public class LabelDemo
  7. {
  8.    public static void main( String args[] )
  9.    {
  10.       // Create a label with plain text
  11.       JLabel northLabel = new JLabel( "North" );
  12.  
  13.       // create an icon from an image so we can put it on a JLabel
  14.       ImageIcon labelIcon = new ImageIcon( "C:\\Users\\george bush\\Desktop\\ring_sat.GIF" );
  15.  
  16.       // create a label with an Icon instead of text
  17.       JLabel centerLabel = new JLabel( labelIcon );
  18.  
  19.       // create another label with an Icon
  20.       JLabel southLabel = new JLabel( labelIcon );
  21.  
  22.       // set the label to display text (as well as an icon)
  23.       southLabel.setText( "South" );
  24.  
  25.        // create a frame to hold the labels
  26.       JFrame application = new JFrame();
  27.  
  28.       application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
  29.  
  30.       // add the labels to the frame; the second argument specifies
  31.       // where on the frame to add the label 
  32.       application.add( northLabel, BorderLayout.NORTH );
  33.       application.add( centerLabel, BorderLayout.CENTER );      
  34.       application.add( southLabel, BorderLayout.SOUTH );      
  35.  
  36.       application.setSize( 300, 300); // set the size of the frame
  37.       application.setVisible( true ); // show the frame
  38.    } // end main
  39. } // end class LabelDemo
  40.  
when I replace the GIF with the JPEG version the panel is empty but stillI candisplay text
Jun 11 '08 #3
BigDaddyLH
1,216 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.net.*;
  3. import javax.swing.*;
  4.  
  5. public class ImageTest {
  6.     public static void main(String[] args) {
  7.         EventQueue.invokeLater(new Runnable(){
  8.             public void run() {
  9.                 try {
  10.                     launchGUI();
  11.                 } catch (MalformedURLException e) {
  12.                     e.printStackTrace();
  13.                 }
  14.             }
  15.         });
  16.     }
  17.  
  18.     static void launchGUI() throws MalformedURLException {
  19.         URL url = new URL("http://blogs.sun.com/jag/resource/JagHeadshot-small.jpg");
  20.         JFrame f = new JFrame("ImageTest");
  21.         f.getContentPane().add(new JLabel(new ImageIcon(url)));
  22.         f.pack();
  23.         f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  24.         f.setLocationRelativeTo(null);
  25.         f.setVisible(true);
  26.     }
  27. }
ImageIcon has no problems displaying JPEG images. Perhaps your path is wrong or the file is corrupted.
Jun 11 '08 #4
momotaro
357 100+
thank you nice picture !
but is there any difference if I use uper/lowercase?
does the size of the image matter?
PS: the code is pefectely working on netbeans but as weird as it can sounds it's not working using cmd
Jun 12 '08 #5
momotaro
357 100+
sorry never mind its working now
Jun 12 '08 #6
momotaro
357 100+
now I wanna resize the pic to the demesions of the frame? but can't find any method ??
plz help
Jun 12 '08 #7
BigDaddyLH
1,216 Expert 1GB
now I wanna resize the pic to the demesions of the frame? but can't find any method ??
plz help
Did you look at the methods of Image?
Jun 12 '08 #8
momotaro
357 100+
Did you look at the methods of Image?
there is a method called:
paintIcon(component c, Graphics g, x, y);

but I don't know what c and g are or how to use them!

plz help
Jun 12 '08 #9
BigDaddyLH
1,216 Expert 1GB
there is a method called:
paintIcon(component c, Graphics g, x, y);

but I don't know what c and g are or how to use them!

plz help
Try again: did you look at the methods of Image?
Jun 12 '08 #10
momotaro
357 100+
Try again: did you look at the methods of Image?
thx i think I can figure it out from here ! :)
I was looking at the wrong place
Jun 12 '08 #11

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

Similar topics

1
by: prabhat | last post by:
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...
0
by: Mike | last post by:
Hello, Is there a way of setting text for a JLabel after a certain amount of empty characters. For example, I want to avoid doing this JLabel label = new JLabel(); label.setText(" ...
2
by: reon | last post by:
Hi in this code when i clicked login button...it shows output as login... But when i clicked each time its repeating .. i want to see that only ones ... I want to clear the previous login before...
5
Shinzon
by: Shinzon | last post by:
ok so far I have got: JFrame frame = new JFrame( "Matt's DVD's" ); frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); frame.setSize( 420, 170 ); // set frame size ...
5
Shinzon
by: Shinzon | last post by:
Ok so I have been working on this for a moment now and wondering how to add multiple jlabels to a jframe. the code looks like this: JLabel jl = new JLabel("DVD ID #= " + dvd); //Displays DVD...
3
nanhiPari
by: nanhiPari | last post by:
hello everyone i need to create DYNAMIC JLABElS(say 5)..yes i know it sounds easy but i also have to give them Events n then want to refer each of them when ever Mouse is Clicked on a Specific...
1
by: tommyny04 | last post by:
I have a method addPlayer that's supposed to add a JLabel to a JPanel and update the JPanel. The JLabel is just a label with a player's name in it. The code I've wrote doesn't work and I'm not sure...
6
by: thesti | last post by:
hi, i have a JLabel inside a JPanel of which layout manager is BoxLayout. i will display an image with the JLabel at runtime, when the application first start, it will appear as an empty box...
2
by: Coreyja | last post by:
Im trying to display a png image by setting it as a ImageIcon and then putting that in a JLabel. I cant get it to display the image. I am using a null layout as it is the simplest way for me to get...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.