Imagem sobre Jpanel

4 respostas
O

olá…

to precisando colocar um objeto em cima do otro…tipo:

existe um JPanel, i eu preciso jogar em cima desse JPanel uma imagem em cima dele…i essa imagem será transparente dando o efeito q a imagem está por cima do JPanel (q terá outras coisas dentro dele)…

vlw

4 Respostas

H

Ponha um JLabel na posição que vc quer dentro do JPanel, e no JLabel vc põe a imagem que quiser.

O

eu tentei mais não foi não…qual eh a logica de fazer isso?? obrgiado pela resposta

H

Amigo, vou postar um código onde fiz o que acho que vc quer fazer.
Utilizei o VE do Eclipse, mas pode copiar e colar em qualquer lugar q funciona de boa...

import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

public class teste extends JFrame {

	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JLabel jLabel = null;

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jLabel = new JLabel();
			jLabel.setBounds(new java.awt.Rectangle(74,30,129,78));
			jLabel.setIcon(new ImageIcon("C:/Documents and Settings/Hérick/Meus documentos/Minhas imagens/Google Art/conan_doyle22-5-06.gif"));
			jLabel.setText("JLabel");
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new java.awt.Rectangle(23,15,251,140));
			jPanel.setBackground(new java.awt.Color(152,163,149));
			jPanel.add(jLabel, null);
		}
		return jPanel;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
          teste a = new teste();
          a.setVisible(true);
	}

	/**
	 * This is the default constructor
	 */
	public teste() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJPanel(), null);
		}
		return jContentPane;
	}

}

Espero que seja isso e que eu possa ter ajudado!
Abraço!

Estou editando aqui pq pensei em outra coisa....Vc está querendo inserir uma imagem como se fosse plano de fundo??

Falows!

O

não…estou tentando fazer uma imagem seguir o cursos do mouse, porem essa imagem vai ficar dentro de uma JPanel e quando o mouse clicar nela ai sim ela ira seguir o mouse e ela não estára mais visivel no JPanel pois esta agora junto ao cursor…intendes…t++ i vlw pelo codigo…

Criado 3 de julho de 2006
Ultima resposta 6 de jul. de 2006
Respostas 4
Participantes 2