开发者

Displaying an image on a JtextArea within a JPanel

开发者 https://www.devze.com 2023-03-29 04:55 出处:网络
not sure why 开发者_JS百科this won\'t work i am using netbeans to create it i have similar code in jcreator an it works. any help greatly appreciated

not sure why 开发者_JS百科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" ); 

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.


Try changing the location of image folder for netbeans. I used to use netbeans in my student life. The thing I can remembered, it might be the issue with relative path to the images.

That might be the reason to not work with netbeans only.

0

精彩评论

暂无评论...
验证码 换一张
取 消