Alguem sabe me dizer se eu posso colocar uma imagem gif sobre o text area do jpanel??
e se for possivel como faco isso?
Imagem "sobre" o JtextPanel
5 Respostas
Alguem sabe me dizer se eu posso colocar uma imagem gif sobre o text area do jpanel??
e se for possivel como faco isso?
Vc ta querendo alguma coisa do tipo background ?
Vc ta querendo alguma coisa do tipo background ?
nao…a imagem tem q ficar “sobre” o texto e nao atraz dele como se fosse um mouse…entende
mas se nao tiver geito serve como background
Vc ta querendo alguma coisa do tipo background ?nao…a imagem tem q ficar “sobre” o texto e nao atraz dele como se fosse um mouse…entende
mas se nao tiver geito serve como background
Ve se vc consegue arrancar alguma coisa daqui. Isso ai cria um JTextArea e cria um background pra ele…
import java.awt.*;
import java.awt.image.*;
import javax.swing.border.*;
public class CentredBackgroundBorder implements Border {
private final BufferedImage image;
public CentredBackgroundBorder(BufferedImage image) {
this.image = image;
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
int x0 = x + (width-image.getWidth())/2;
int y0 = y + (height-image.getHeight())/2;
g. drawImage(image, x0, y0, null);
}
public Insets getBorderInsets(Component c) {
return new Insets(0,0,0,0);
}
public boolean isBorderOpaque() {
return true; //because insets are empty
}
}
e
import java.awt.*;
import java.io.*;
import java.net.URL;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.border.*;
public class BackgroundBorderExample {
public static void main(String[] args) throws IOException {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame f = new JFrame("BackgroundBorderExample");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String url = "http://java.sun.com/people/jag/images/JagHeadshot.jpg";
//String url = "http://java.sun.com/people/jag/images/JagHeadshot-small.jpg";
Border bkgrnd = new CentredBackgroundBorder(ImageIO.read(new URL(url)));
JTextArea area = new JTextArea(24,80);
area.setForeground(Color.WHITE);
area.setOpaque(false);
area.read(new FileReader(new File("c:\teste.txt")), null);
JScrollPane sp = new JScrollPane(area);
sp.setBackground(Color.BLACK);
sp.setViewportBorder(bkgrnd);
sp.getViewport().setOpaque(false);
f.getContentPane().add(sp);
f.setSize(600,400);
f.setVisible(true);
}
}
Retirei isso desse link
Caro rogeriovaz assim que chegar em casa eu te mando um exemplo de
classe que criei que tem um metodo paras vc colocar uma imagem com bakground em um JPanel
Cria uma classe extendendo o JPanel e sobrescreve o paint(), chama o super antes e depois umas o Graphics e poe tua imagem la.