Colocar Figura

3 respostas
F

Alguem poderia me ajudar, estou tentando colocar uma figura numa Label, mas a figura não carrega. Já tentei algumas coisas como:

  • A figura já está na mesma pasta das minha classes;

  • O tamanho da Label é maior que a figura;

  • Já criei o seguinte código:

ImageIcon image = new ImageIcon( "McCulloch.gif" ); jLabel.setIcon(image);

Mas a figura não carrega. Alguem poderia por favor poderia ver se tem uma solução.

Desde de já obrigado. :lol:

3 Respostas

furutani

Só para teste, tente jocar a figura em C: ImageIcon image = new ImageIcon( "C:/McCulloch.gif" ); jLabel.setIcon(image);
Veja se isso funciona. Se funcionar o problema é o caminho, ai eu recomendo vc usar o getResourceAsStream();

F

Naum deu certo!!

Lex-dmm

Cara aqui tem um exemplo do que eu fiz. Pega ai, qualquer coisa da um toque.

/*
 * Created on 24/06/2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package src.com.datasul.gui;

import java.awt.Color;
import java.awt.Container;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

/**
 * @author tech1023
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class About extends JFrame {
	
	public JPanel panel,panelBackGound;;
	public Container cont;
	public CellConstraints cc;
	
	/**
	 * 
	 */
	public About(){
		super(":: About SuportBar ::");
		
		cont = this.getContentPane();
			    	    
	    // Seta icone
	    Image icon = Toolkit.getDefaultToolkit().getImage("src/com/datasul/icons/Battery.gif");
	    this.setIconImage(icon); 
	    this.setResizable(false);
	    	    
	    panelBackGound = new JPanel();
	    panel = new JPanel();
	    Icon ic = new ImageIcon("src/com/datasul/icons/logo.jpg");	
	    JLabel img = new JLabel(ic);
		panel.add(img);
	    	    
		//Trata o layout
		panelBackGound.setLayout(new FormLayout("1dlu, center:pref, 1dlu", 
	    									"4dlu, pref, 2dlu, " +
	    									"pref, 2dlu," +
	    									"pref, 2dlu," +
	    									"pref, 4dlu,"));				
		cc = new CellConstraints();
		
		//seta o layout corretamente conforme posições.
		panelBackGound.add(new JLabel("SuportBar v 1.0"),    cc.xy(2, 2));
		panelBackGound.add(panel,                            cc.xy(2, 4));		
		panelBackGound.add(new JLabel("Datasul Tecnologia"), cc.xy(2, 6));
		panelBackGound.add(new JLabel("Powered by Lex"),     cc.xy(2, 8));
		panelBackGound.setBackground(new Color(192,192,192));
		cont.add(panelBackGound);		
		
		this.show();
		this.pack();
	}
}
Criado 29 de julho de 2005
Ultima resposta 1 de ago. de 2005
Respostas 3
Participantes 3