在JPanel内的JtextArea上显示图像 [英] Displaying an image on a JtextArea within a JPanel
本文介绍了在JPanel内的JtextArea上显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不知道为什么这行不通我正在使用netbeans创建它,我在jcreator中有类似的代码并且它可以工作.任何帮助表示赞赏
not sure why this won't work i am using netbeans to create it i have similar code in jcreator an it works. any help greatly appreciated
public void BoardGUI(){
panel = new JPanel();
setIconImage(new ImageIcon("images/die.bmp").getImage());
Container cPane;
cPane = getContentPane();
cPane.setBackground(Color.red);
setTitle("ITT Game Of Life");
setDefaultCloseOperation(EXIT_ON_CLOSE);
panel.setOpaque(false); //the frame
setSize(800,650);
setLocation(500,100);
boardArea = new JTextArea(50,100) {
ImageIcon image = new ImageIcon( "/images/Board.jpg" );
@Override
public void paint( Graphics g ) {
g.drawImage( image.getImage(), 0, 0, this);
super.paint(g);
}
};
boardArea.setOpaque(false);
boardArea.setEditable(true);
boardArea.setBounds(100,50,200,200);
cPane.add(boardArea);
推荐答案
setIconImage(new ImageIcon("images/die.bmp").getImage());
ImageIcon image = new ImageIcon( "/images/Board.jpg" );
您使用了2种不同的方法来具体化图像的位置.我想第一个是正确的.您的边框图标改变了吗?
You used 2 different ways to spcify the location of the image. I would guess the first is correct. Did your frame icon change?
此外,如何使用图标教程可以提供更好的效果图片作为资源的示例.
Also, the How to Use Icons tutorial gives better examples by the the image as a resource.
这篇关于在JPanel内的JtextArea上显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文