java - getting uknown error -


OK, then there is an assignment:

Create a simple image viewer that will allow the user to click Select an image from a button and then the file system and the image is displayed in JLabel.

Here I have the code:

  import java.awt.event .ActionEvent; Import java.awt.event.ActionListener; Import java.io.file; Import javax.swing.ImageIcon; Import javax.swing.JButton; Import javax.swing.JFileChooser; Import javax.swing.JFrame; Import javax.swing.JLabel; Public Class Main implementation ActionListener {JButton openButton; JFileChooser FC; File filename; JLabel image; Jeff Frames; Public Main () {frames = new JFrame ("Picture Viewer"); Frame.setBounds (100,100,750,750); Frame.setLayout (zero); Frame.setVisible (true); OpenButton = New pocket ("Choose an image to display ..."); OpenButton.setBounds (0,0,750,50); OpenButton.setLayout (zero); OpenButton.setVisible (true); Frame.add (openButton); OpenButton.addActionListener (this); } Public static zero main (string [] args) {main = new main (); } @ Override Public Zero Action Perfid (ActionAge RGET) {FC = New Jeffile Cluster (); Fc.showOpenDialog (zero); FileName = fc.get selected file (); Image icon icon = new image (filename.gatepath ()); Image = new jquery (icon); Image.setBounds (15,65,720,655); Image.setLayout (zero); Image.setVisible (true); Frame.add (image); }}  

and getting the error here:

  sun.awt.image.ImageFormatException: unsupported color conversion requests at sun.awt. Sun.awt.image.InputStreamImageSource.doFetch at sun.awt.image.ImageFetcher.fetchloop (unknown source) image on sun.awt.image.JPEGImageDecoder.produceImage (unknown source). Sun.awt.image.imagefetcher.run (unknown source) on JPEGImageDecoder.readImage (unknown method)  

It may be that your JPEG is using CMYK color model instead of RGB. There are some suggestions for dealing with that.

To verify it, try another JPEG, which you know RGB.

EDIT: You are not using layout with your frame. Instead of

  frame.Seletout (null);  

Try

  frame. Setout (new border layout ());  

After that, when you create a picture label, shape the size of the icon size. E.g.

  image.setWidth (icon.getIconWidth ()); Image.setHeight (icon.getIconHeight ()); Frame.add (Image, Border Layout. CA);  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -