2011-08-17 102 views
1

不确定为什么这不起作用我正在使用NetBeans创建它,我在jcreator中有类似的代码。任何帮助非常感谢在JPanel内的JtextArea上显示图像

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); 
+1

你有什么错误吗?什么不工作?当我尝试它时,我可以看到图像作为文本区域的背景。 – 2011-08-17 12:12:22

+0

没有错误出现,只是当我运行它我没有得到图像apper根本。我应该将图像放在类中,还是放在项目中其他位置的文件夹中。 – Cian 2011-08-17 13:38:07

回答

1
setIconImage(new ImageIcon("images/die.bmp").getImage()); 

ImageIcon image = new ImageIcon("/images/Board.jpg"); 

你用两种不同的方式来spcify图像的位置。我想第一个是正确的。你的框架图标改变了吗?

另外,How to Use Icons教程提供了更好的图像作为资源的例子。

0

尝试更改netbeans的图像文件夹的位置。我曾经在学生生活中使用netbeans。我记得的事情,这可能是与图像相对路径的问题。

这可能是不能使用netbeans的原因。