2011-09-08 46 views
3

這裏是代碼。不知道爲什麼文本區域不顯示背景圖像JTextArea繪製Java?

import java.awt.*; 


import javax.swing.*; 





public class UserInterface extends JFrame { 
public static void main(String[] args){ 
    System.out.print("Yes the application is working!"); 
    drop(); 
} 

public static void drop(){ 
    javax.swing.JFrame frame = new javax.swing.JFrame("FileDrop"); 
    //javax.swing.border.TitledBorder dragBorder = new javax.swing.border.TitledBorder("Drop 'em"); 
    JTextArea text = new JTextArea(){ 

      {setOpaque(false);} 
      public void paint (Graphics g) 
      { 
        ImageIcon ii=new ImageIcon("/Users/tushar_chutani/Downloads/Play1Disabled.png"); 
        Image image= ii.getImage(); 

        g.drawImage(image,0,0,null,this); 
        super.paintComponent(g); 
      } 
     }; 


    frame.setBounds(50, 50, 167, 167); 
    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); 
    frame.setVisible(true); 

} 
} 

這是整個代碼。 任何幫助,將apritiated

感謝, TC

回答

3

主要的問題是,你沒有文本區域添加到框架。

其他問題是,您應該調用paint(),而不是從overriden paint()方法調用paintComponent()。

另外,您不應該在paint()方法中讀取圖像。

+0

好的,謝謝抱歉,這樣的stuid問題 –