Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTextArea painting Java?

here is the code. don't know why the text area isn't showing the backgroud image

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

}
}

this is the entire code. any help would be apritiated

thanks, TC

like image 506
Tushar Chutani Avatar asked Mar 09 '26 16:03

Tushar Chutani


1 Answers

The main problem is that you didn't add the text area to the frame.

Other problems are that you should be invoking paint(), not paintComponent() from the overriden paint() method.

Also, you should not read the image in the paint() method.

like image 52
camickr Avatar answered Mar 12 '26 15:03

camickr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!