Re: Problem with images



gaijinco wrote:
Hi!

I'm having a really frustrating problem with displaying images: the
problem is that when I created a GUI (using swing) the images doesn't
appears until I made the slightest change to the size of the window.

For the image, I'm using a JLabel with the setIcon() method.

I have tried all kinds of Layout Managers and all kind of combinations
of sizes for all elements (JFrame, JPanel's, JLabel's, etc) but
nothing seems to work.

Does somebody knows what may be happening?

Thank you very much!

This is my exact code:

public class InterfazCrucigrama extends JFrame {

private JLabel panelImagen;

public InterfazCrucigrama() {
setTitle( "Crucigrama" );
getContentPane( ).setLayout( new BorderLayout(10,10) );
setSize( 800, 600 );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setVisible(true);

panelImagen = new JLabel("");
panelImagen.setIcon(new ImageIcon("data/imagenes/
titulo.png"));
getContentPane().add(panelImagen, BorderLayout.NORTH);
}

public static void main(String[] args) {
InterfazCrucigrama miCrucigrama = new InterfazCrucigrama();
}
}


I'm not an expert, but I think you have "setVisible" in the wrong spot. Call that after all of the components get added.

Also, call pack() before setVisible but after all of the other components have been added. pack() is the standard way of telling a window that it's about ready to be drawn.
.



Relevant Pages

  • Problem with images
    ... I'm having a really frustrating problem with displaying images: ... public class InterfazCrucigrama extends JFrame { ...
    (comp.lang.java.programmer)
  • Re: Pictures saved from Adobe CS3
    ... latest service pack. ... Fixing PowerPoint Annoyances http://tinyurl.com/36grcd ... uninstall this latest service pack and risk a security issue. ... they're just showing up now because of something in the CS3 images, ...
    (microsoft.public.powerpoint)
  • Re: Small Project
    ... What kind of objects, what size images? ... that'll they can be fairly low res images, thus you can try to pack them ... and use texture addressing to reduce the number of ... > with about 10 possible images to display on each object. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: average of PIL images
    ... images is tricky; you really shouldn't do it in the RGB colorspace. ... thanx for the guidance and detailed replies..I tried to pack the ...
    (comp.lang.python)
  • Re: Synth in a jar
    ... When i pack it to a jar and use it in another ... application these images can not be read. ... the images is managed by the synth api. ...
    (comp.lang.java.gui)