Displaying image in jlabel

when displaying an image in a jlable. the jlabel takes on the size of the image. i have tried to set the maximum bounds to the size of the original size of the jlable and even the panel the jlable sits on, but each time that i go to display the picture, it is displayed huge and not the size of the jlabel it is placed in.
here is my creation code, my gui was created in netbeans.
pnImage.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnImage.setFocusable(false);
        pnImage.setMaximumSize(new java.awt.Dimension(395, 365));
        lblImage.setFocusable(false);
        lblImage.setMaximumSize(new java.awt.Dimension(395, 365));
        javax.swing.GroupLayout pnImageLayout = new javax.swing.GroupLayout(pnImage);
        pnImage.setLayout(pnImageLayout);
        pnImageLayout.setHorizontalGroup(
            pnImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblImage, javax.swing.GroupLayout.PREFERRED_SIZE, 393, javax.swing.GroupLayout.PREFERRED_SIZE)
        pnImageLayout.setVerticalGroup(
            pnImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblImage, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
        );and here is how i display it.
        Dimension d = pnImage.getSize();
        System.out.println("d = " + d.toString());
        pnImage.setMaximumSize(d);
        lblImage.setMaximumSize(d);
        ImageIcon icon = new ImageIcon(contact.getImage());
        lblImage.setIcon(icon);

I've never done this (convert a byte array to an image), so I thought I'd have a go...import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
public class ImageTest {
    public static void main(String[] args) throws Exception {
            // Grab some image...
        File inFile = new File("resources/imageH.jpg");
        int len = (int)inFile.length();
        System.out.printf("file length = %d%n", len);
        FileInputStream in = new FileInputStream(inFile);
            // ... and create a byte array for testing
        byte[] byteArray = new byte[len];
        int num = in.read(byteArray);
        in.close();
        System.out.printf("bytes read = %d%n", num);
            // (1) Create an image from the byte array - I don't
            // know Imagio figures out what sort of image it is!
        BufferedImage im = ImageIO.read(new ByteArrayInputStream(byteArray));
        int w = im.getWidth();
        int h = im.getHeight();
        System.out.printf("width = %d, height = %d", w, h);
            // (2) Scale to fit 100x100
        if(w > h) {
            w = (100 * w) / h;
            h = 100;
        } else {
            h = (100 * h) / h;
            w = 100;
        System.out.printf(" --> %d,%d%n", w, h);
            // (3) And create the icon
        ImageIcon icon = new ImageIcon(im.getScaledInstance(w, h, Image.SCALE_SMOOTH));
        System.out.printf("The icon is: %s%n", icon);
}The output isfile length = 54918
bytes read = 54918
width = 500, height = 300 --> 166,100
The icon is: javax.swing.ImageIcon@5afd29Assuming your byte array is some (to ImageIO) recognisable image format, something
similar should work for you.

Similar Messages

  • Displaying Image using JLabel in swings

    I am not understanding how to display a image in swing using JLabel Component.
    I am writing in the following manner:
    // importing necessary packages
    in init() method
    public void init()
    Container cp= getContentPane()
    JLabel jl=new JLabel("Image",new ImageIcon("<image>.gif"),JLabel.CENTER);
    cp.add(jl);
    applet is running and only label msg is displaying but not the image.
    Please help me so that i can solve this problem.where the image is to be placed??and how it has to be included?
    Please provide me the solution.

    cp.add(new JLabel("Image",new ImageIcon(new java.net.URL (getCodeBase(),"Test.gif")),JLabel.CENTER));

  • Problem in displaying images using JLabel in Netbeans

    hi all,
    i am trying to display an image on JLabel in Netbeans.The image is visible in the design view but not displayed in the runtime.Can anyone help me out with suggestions???

    Duplicate - answer here http://forum.java.sun.com/thread.jspa?threadID=5153605&messageID=9578626#9578626

  • Question about displaying image with JLabel

    Hi
    I need to display an image. The image is determined by the user at run time, so the dimension of the image is unknown. Is it possible for JLabel to stretch the image so the whole image(instead of only part of it) will always fits into a certain dimension?
    thanks.

    For this you need to create a custom class that extends ImageIcon
    and define the methods there.
    see Java Tutorial for it.
    For eg., to scale an image , you can use
    JLabel label = new JLabel();
    Image img = new ImageIcon("Pics/Ash.jpg").getImage();
    int width = img.getWidth(null);
    int height = img.getHeight(null);
    //This would scale the Image by 200%
    Image bimg = image.getScaledInstance(width*2, height*2, Image.SCALE_SMOOTH);
    label.setIcon(new ImageIcon(bimg));
    //There is also another way
    //Use drawImage and use BufferedImage
    BufferedImage buff = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics g = buff.getGraphics();
    //Scale the Image to 200%
    g.drawImage(img, 0, 0, width*2, height*2,  null);
    lable.setIcon(new  ImageIcon(buff));Hope you get the idea!!

  • Displaying images in jlabel, jpanel

    Hi all,
    below is my snippet:
    public void actionPerformed(ActionEvent e)
            lblImage.setIcon(new ImageIcon("c:/test"+cnt+".jpg";));
            cnt++;
            if(cnt==6)
                cnt=1;               
            repaint();
        }this actionPerformed() is executed for every 2 seconds. i am displaying continuously 5 pictures in a loop (c:/test1.jpg, c:/test2.jpg...). 5 images are displaying properly. But, they are not of newly updated jpg files. Files used for the 1st loop are used continuously irrespective of newly created files in c: (I am updating these 5 files in c: with another program, updation is proper.). how to show the files properly so that to get motion movie simulation.
    please do help.
    thanking you.
    _________________________

    Don't cross post or you won't get help in future. already answered on
    [http://forums.sun.com/thread.jspa?threadID=5340639]
    db

  • Open and display image in MVC layout

    Hello!
    I cant figure out how I shall do this in an MVC layout:
    The program request user to open an image file that are then displayed in a JLabel
    My setup at the moment resolve in a nullpointerexeption because it dont get any actual image file, but I dont understand what I have missed.
    I can not post the whole code fo you to run because it is to big, so I post the part that are the most important. please have a look.
    PicturePanel
    //Import Java library
    import javax.swing.*;
    import java.awt.*;
    public class PicturePanel extends JPanel {
         //Variables
         private ImageIcon picture;
         //Method to get information of the selected file
         PicturePanel (String fileName) {
              picture = new ImageIcon (fileName); //Get the filename
              int w = picture.getIconWidth(); //Get the image with
              int h = picture.getIconHeight(); //Get the image height
              //Set preferable size for the image (Use the properties for the selected image)
              setPreferredSize(new Dimension(w, h));
              setMinimumSize(new Dimension(w, h));
              setMaximumSize(new Dimension(w, h));
         //Method to draw the selected image
         protected void paintComponent(Graphics g) {
              super.paintComponent(g); //We invoke super in order to: Paint the background, do custom painting.
              g.drawImage(picture.getImage(), 0, 0, this); //Draw the image at its natural state
    }From my model:
    //Local attributes
         boolean check = false; //Used to see if a statement is true or not
         PicturePanel pp;
         JFileChooser fc;
         int returnVal;
    //newFile in File menu
         public void newFile() {
              //Open a file dialog in users home catalog
              fc = new JFileChooser();
              //In response to a button click:
              returnVal = fc.showOpenDialog(pp);
              System.out.println("You pressed new in file menu");
         }From my controler:
    //User press "New" in File menu
              else if (user_action.equals("New")) {
                   //Call method in model class
                   model.newFile();
                   //Update changes
                   if (model.returnVal == JFileChooser.APPROVE_OPTION) {
                        System.out.println("Hello1");
                        File f = model.fc.getSelectedFile();
                        if (model.pp != null)     
                             model.pp = new PicturePanel(f.getAbsolutePath());
                        System.out.println("Hello2");
                        //Display image (Here is line 83)
                        view.setImage_DisplayArea(model.pp);
                        System.out.println("Hello3");
              }From my view:
    //Sets the image to be displayed on the image_display area (Here is line 302)
         public void setImage_DisplayArea(PicturePanel pp) {
              image_display.add(pp);
         }The complet error:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
         at java.awt.Container.addImpl(Container.java:1015)You pressed new in file menu
    Hello1
    Hello2
         at java.awt.Container.add(Container.java:351)
         at View_Inlupp2.setImage_DisplayArea(View_Inlupp2.java:302)
         at Control_Inlupp2.actionPerformed(Control_Inlupp2.java:83)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1882)
         at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2202)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
         at javax.swing.AbstractButton.doClick(AbstractButton.java:334)
         at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1050)
         at apple.laf.CUIAquaMenuItem.doClick(CUIAquaMenuItem.java:119)
         at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1091)
         at java.awt.Component.processMouseEvent(Component.java:5602)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3129)
         at java.awt.Component.processEvent(Component.java:5367)
         at java.awt.Container.processEvent(Container.java:2010)
         at java.awt.Component.dispatchEventImpl(Component.java:4068)
         at java.awt.Container.dispatchEventImpl(Container.java:2068)
         at java.awt.Component.dispatchEvent(Component.java:3903)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3936)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
         at java.awt.Container.dispatchEventImpl(Container.java:2054)
         at java.awt.Window.dispatchEventImpl(Window.java:1801)
         at java.awt.Component.dispatchEvent(Component.java:3903)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)Edited by: onslow77 on Dec 16, 2009 5:00 PM
    Edited by: onslow77 on Dec 16, 2009 5:04 PM

    Hello again!
    Anyone that can help me figure out how to implement this in an MVC layout, I feel stuck.
    I post a little program that open and display an image file so that you better can understand what I whant to do.
    ShowImage
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    import javax.swing.filechooser.*;
    public class ShowImage extends JFrame{
         //Variables
         JFileChooser fc = new JFileChooser();
         PicturePanel pp = null;
         ShowImage () {
              super("Show"); //Title
              //Create the GUI
              JPanel top = new JPanel();
              add(top, BorderLayout.NORTH);
              JButton openBtn = new JButton("Open");
              top.add(openBtn);
              openBtn.addActionListener(new Listner());
              //Settings for the GUI
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              pack();
              setVisible(true);
         class Listner implements ActionListener {
              public void actionPerformed(ActionEvent ave) {
                   int answer = fc.showOpenDialog(ShowImage.this);
                   if (answer == JFileChooser.APPROVE_OPTION){
                        File f = fc.getSelectedFile();
                        //Check
                        System.out.println(f);
                        System.out.println(pp);
                        if (pp != null)
                             remove(pp); //Clean so that we can open another image
                        //Check
                        System.out.println(pp);
                        //Set the PicturePanel
                        pp = new PicturePanel(f.getAbsolutePath());
                        //Check
                        System.out.println(pp);
                        //Add PicturePanel to frame
                        add(pp, BorderLayout.CENTER);
                        validate();
                        pack();
                        repaint();
         //Main
         public static void main(String[] args) {
              new ShowImage();
    }PicturePanel
    //Import Java library
    import javax.swing.*;
    import java.awt.*;
    public class PicturePanel extends JPanel {
         //Variables
         private ImageIcon picture;
         //Method to get information of the selected file
         PicturePanel (String fileName) {
              picture = new ImageIcon (fileName); //Get the filename
              int w = picture.getIconWidth(); //Get the image with
              int h = picture.getIconHeight(); //Get the image height
              //Set preferable size for the image (Use the properties for the selected image)
              setPreferredSize(new Dimension(w, h));
              setMinimumSize(new Dimension(w, h));
              setMaximumSize(new Dimension(w, h));
         //Method to draw the selected image
         protected void paintComponent(Graphics g) {
              super.paintComponent(g); //We invoke super in order to: Paint the background, do custom painting.
              g.drawImage(picture.getImage(), 0, 0, this); //Draw the image at its natural state
    }//The endEdited by: onslow77 on Dec 16, 2009 7:30 PM

  • Problem Displaying Images in a JFrame

    I am writing a program that displays images on a JFrame window. I have been reading the other postings about this topic however I have not been able to make my code work. I am hoping there is some obvious solution that I am not noticing. Please help, I am very confused!
    public class WelcomeWindow {
    private JLabel label;
    private ImageIcon logo;
    public WelcomeWindow() {
    label = new JLabel();
    logo = new ImageIcon("/images/logo.gif");
    label.setIcon(logo);
    this.getContentPane().add(label);

    Instead of a JLabel, have you tried to use a JButton containing the Icon?
    Also (but I think you've done it already), you could do that :
    File iconFile = new File("/images/logo.gif");
    if (!iconFile.isFile()) {
    System.out.println("Not a file");
    That way you'll be certain that the path given is correct.
    Hope this helps.

  • Whats the best way to manage/display images ?

    I'm building a yet another photo management application that is designed to be a Picasa2 "lite". I've got a lot of JPGs I need to manage, all of which are loaded asynchronously and cached over the web.
    The same image may appear in multiple places, (i.e. thumbnail, fullsize, original with a zoom box, etc.) I'm having problems keeping all these images in synch when I change the underlying image -- right now I have to create all new JLabels for everything and add them to their respective Panels again. But that doesn't seem like its the best way.
    Here's my JLabel sub-class:
    public class ImageLocatorSubscriber extends JLabel {
         public final ImageDimEnum maxDimEnum;
         final ImageIcon imgIcon = new ImageIcon();
         BufferedImage bi;
         ImageLocator il;
         public ImageLocatorSubscriber(ImageLocator il, ImageDimEnum d) {
              super();
              this.maxDimEnum = d;
              this.imgIcon = new ImageIcon();
              if (il != null) {
                   this.il = il;
                            this.bi = il.getBi(RunMode.NOWAIT);
                      if (bi.getWidth()!=maxDimEnum.dim.getWidth() || bi.getHeight()!=maxDimEnum.dim.getHeight()) {
                           bi = FotoFix.resize(bi, maxDimEnum.dim);
                      this.bi = bi;
                      this.imgIcon.setImage(this.bi);
                      this.setSize(bi.getWidth(), bi.getHeight());
              this.setIcon(this.imgIcon);
              this.setBorder(Constants.borderGray);
         }Is the preferred method for changing the image displayed in a JLabel
    a) create a new ImageIcon and use (JLabel) this.setIcon()
    b) reuse the existing ImageIcon and use (JLabel) this.imgIcon.setImage();
    c) remove the old JLabel from the panel, create a new JLabel, and add that to the panel?
    I can only get c) to work. When I try to use b) some of the images are not updated properly, even as I have declared this.imgIcon as final. Any ideas, or should I just leave it be?

    override this method in any JComponent subclass
    http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#paintComponent(java.awt.Graphics)

  • Changing images in JLabels

    I am creating a program which needs to display a grid of 7 by 7 images, as i am new to swing and fairly new to java i decided to use JLabels to show these images.
    I also need to be able to change these images, when buttons are clicked, i have set up the listeners for the buttons and the initial grid is correct however i cannot get the images to change?
    The JLabels are done as an array so each JLabel can be identified seperately.
    I have tried changing the labels eg Images=new JLabel("newimage.gif");
    and also I have tried creating other JLabels and doing things like
    Images[i]=newLabel //newLabel has the icon i want to use.
    I have repainting the screen and if i use the setText method on the JLabels then the text is displayed, however new images aren't
    do i need to not use JLabels, if so what can i use to do this?

    i tried using the setIcon function on my screen capture program and was unable to get it to update the image as long as the old image file was the same filename as the new image file. however if you change the image file name i got it to work fine......you just can't refresh an image of the same name if you've changed the content......

  • PaintComponent method doesn't display anything on JLabel?

    I am trying to show a histogram for a image in jlabel, but its not working.
    //hist : array containing histogram values
    //wid: width of image
    //ht: height of image
    mylabel.add(new showData(hist,wid,ht));
    The code that I am using to display histogram is:
    class showData extends JLabel{
    int w,h;
    int hist[] = new int[256];
    int max_hist=0;
    public showData(int[] histValue,int w, int h) {
    System.arraycopy(histValue, 0, hist, 0, 256);
    this.w = w;
    this.h = h;
    for (int i = 0; i < 256; i++) {
    if(hist>max_hist)
    max_hist=hist[i];
    @Override
    protected void paintComponent(Graphics g)
    super.paintComponent(g);
    int x = (w - 256) / 2;
    int lasty = h - h * hist[0] / max_hist;
    for (int i=0; i<256; i++, x++) {
    int y = h - h * hist[i] / max_hist;
    g.setColor(new Color(i, i, i));
    g.fillRect(x, y, 1, h);
    g.setColor(Color.red);
    g.drawLine(x-1,lasty,x,y);
    lasty = y;
    When debugged, I found that showData() method was getting invoked, but paintComponent() doesn't. Why is it so? The Jlabel 'mylabel' doesn't show anything?

    Check size and location of the JLabel. If size 0 the paintComponent() is not called. Try to set preferred size to the label.

  • Won't display images - Its probably something simple!

    Hey ,
    Ive been trying for ages, looked throught the tutorials (i have even tried just using java pasted from the site for one of the simple programs) and looking through old forum questions but can't find out why my GUI wont display images. It compiles fine but then when i run the program ... no pics!
    I suspect its something to do with the directory, i have tired:
    - putting the images in the same directory as the java classes,
    - putting in the entire image location paths (for this i get illegal characters error because it has '\' in the path but i get round this using '\\' ) but still no joy.
    Like i said am just using the example programme from the site so i know its correct, Any ideas??
    Thanx
    Lisa

    Here is a simple program to test:
    JFrame frame = new JFrame();
    JLabel label = new JLabel("image.jpg");
    frame.getContenPane()..add( label );
    frame.pack();
    frame.setVisible(true);a) Place "image.jpg" is the same directory as the source and class files.
    b) Don't use any package names for you class.
    c) Compile using javac, not through and ide or anything.
    d) Make sure your classpath includes ".", so it will search the current directory.

  • How to display  image efficiently in JPanel.............

    i have following piece of code used to load and display image on jpanel when application starts.
    the problem is that
    image is not loaded efficiently,
    also it covers other panels added in frame.
    and scrollbar of panel does not work to show parts of image.
    i want to efficiently load the image and to fit in in my panel and also to scroll bar to work proper with image.
    looking for any nice suggestion
    public class MainFrame extends JFrame
    Image image = Toolkit.getDefaultToolkit().createImage("c:\\form-3.jpg");
    javax.swing.JScrollBar jScrollBar1 = new JScrollBar();
    BorderLayout borderLayout1 = new BorderLayout();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    public MainFrame()
    try
    {            jbInit();        } catch (Exception ex)
    {            ex.printStackTrace();        }
    public static void main(String[] args)
    MainFrame mainFrame = new MainFrame();
    jBInit Method defined here
    public void paint(Graphics g)
    g.drawImage(image,0,0,jPanel1);
    Message was edited by:
    @tif

    You have overided the paint method on JFrame then you are drowing on entire Frame.
    Instead you have to override the paintComponent method of a JPanel class or use a JLabel with the image

  • Fit image to JLabel or JButton

    I have searched the topic and found some instances of the Image package being used to resize images.
    I have a DB of images (think photos) that I want to display based on user input. The display size will be the same but the actual picture dimensions stored in the DB won't necessarily be.
    My experience is that the amount of image displayed in the JLabel is entirely based on the size of the image itself (i.e. a small image is completely displayed while a large image is partially displayed.
    I wish to have the image fit to the JLabel (or JButton) dynamically.
    Is there an obvious method I am overlooking?
    TIA,
    Sil

    Here is the code for getting the image from the DB. As you can see it is a byte[].
    private static byte[] image = retrieveImage2;
    private static byte[] retrieveImage2() throws Exception
            String query = "SELECT GifBlob FROM Blobfile WHERE Name = ?";
            ResultSet rs = null;
            PreparedStatement pstmt = null;
            Blob blob = null;
            try
               pstmt = conn.prepareStatement(query);
               pstmt.setString(1,"7.jpg");
               rs = pstmt.executeQuery();
               rs.next();
               blob = rs.getBlob("GifBlob");
               byte[] gifBlob = blob.getBytes(1, (int) blob.length());
               return gifBlob;
            }I then call the method to place the image on the JLabel
    public void addImage(byte[] byteImage) {  
            javax.swing.Icon iconImage = new javax.swing.ImageIcon(byteImage);
            jLabel1.setIcon(iconImage);I don't see where I can set the size of an ImageIcon. Should I be using a different way of converting the image?
    Thanks again,
    Sil

  • Images in jlabel -further query to peio1 and evert1234

    hi,
    I found a problem in bringing out images in jlabel.
    thanks for evert1234 for your reply.
    thanks for peio for your sample code.
    I found an error "cannot resolve symbol"
    for frame.getContentPane().I extended JFrame in the
    class I implemented this init() method.
    getContentPane is working correctly when called simply.
    Being a UG student undertaking a training in java
    swings I have a little maturity in java bugs.
    please guide me.
    yours friendly,
    mohan raj

    Hello ,
    try to no rewritte a new topic for a same problem. You have only to do a reply..
    For your problem try the further source.. I think it will help you
    // ImageLabelExample.java
    // Variations on a text & icon label.
    import javax.swing.*;
    import java.awt.*;
    public class ImageLabelExample {
    // put your address ICON
    private static Icon icon = new ImageIcon("images/smile.gif");
    public static void main(String[] args) {
    JLabel l;
    // create JLabel
         l=makeLabel(JLabel.TOP,JLabel.LEFT);
    // Add the labels to a frame and display it
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c = frame.getContentPane();
    c.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3));
    c.add(l);
    frame.setSize(350,150);
    frame.setVisible(true);
    protected static JLabel makeLabel(int vert, int horiz) {
    JLabel l = new JLabel("Smile", icon, SwingConstants.CENTER);
    l.setVerticalTextPosition(vert);
    l.setHorizontalTextPosition(horiz);
    l.setBorder(BorderFactory.createLineBorder(Color.black));
    return l;
    Do not forget to give the Duke Dollars ;)
    Thanks
    Best regards

  • What is the best way to display image ??

    hi my questions is unusual, there are so many ways to display images.
    I m developing image processing s/w can any one suggest me which would be the best way to display image on which i can perform image operations.
    like in JPanel, icon, trhough paint() or anything else...
    thank you..In advance

    hi man... i think so imaging is better with JAI(Java Advanced Imaging) .... is perfect for display in jcomponent like JPanel or JLabel, you have to replace the paintComponent().
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.geom.AffineTransform;
    import javax.media.jai.PlanarImage;
    import javax.swing.JComponent;
    class ImagePanel extends JComponent {
         protected PlanarImage image1;
         protected AffineTransform atx= new AffineTransform();
         protected int width, heigth;
         public ImagePanel() {
         public ImagePanel(PlanarImage i) {
              image1= i;
              width= i.getWidth();
              heigth= i.getHeight();
         public void paintComponent(Graphics gc) {
              Graphics2D g= (Graphics2D)gc;
              Rectangle rect= this.getBounds();
              if ((width != rect.width) || (heigth != rect.height)) {
                   double magx= rect.width / (double)width;
                   double magy= rect.height / (double)heigth;
                   atx.setToScale(magx, magy);
              if (image1 != null)
                   g.drawRenderedImage(image1, atx);
    if you need more info, ask about JAI api and docs

Maybe you are looking for

  • While importing, playback is crap

    i like to listen to my cd as it's importing... it worked fine until i hit a song that locked up my pc... now when i try to listen and import the playback is slow and reverberatingish (echoy)... anyone else have this problem, and if so how to fix it..

  • Duplicate records in a collection

    Hi Experts, Just now I've seen a thread related to finding duplicate records in a collection. I understand that it is not advisable to sort/filter data in a collection. (https://forums.oracle.com/thread/2584168) Just for curiosity I tried to display

  • Slicing a CLOB

    I am pulling from what is equivalent to a CLOB in Oracle from a Sybase table. Is there a way I can select only part of the CLOB for a particular id? This CLOB has comments for all ids. However I need to be able to pull a comment for each id. I have a

  • Safari always in idle mode

    Hello, when i start Safari it shows me the spinning volleyball and Safari is idle. When I shut it down I get the following error message: Date/Time:       2011-11-19 10:54:15 +0100 OS Version:      10.7.2 (Build 11C74) Architecture:    x86_64 Report

  • Need help in registering HFM Sample applications with Shared Services

    Hi all, I have installed HFM 9.3.1 on the server and I have issues in locating the sample application in the HFM console. I want to register the sample application with Hyperion shared services. But when I tried opening the application, I do not see