编程语言
首页 > 编程语言> > JTextArea画Java吗?

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

}
}

这是完整的代码.
任何帮助都将被赋予

谢谢,
TC

解决方法:

主要问题是您没有将文本区域添加到框架.

其他问题是您应该从覆盖的paint()方法中调用paint(),而不是paintComponent().

另外,您不应该在paint()方法中读取图像.

标签:jtextarea,swing,java,user-interface
来源: https://codeday.me/bug/20191208/2087859.html