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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
主要问题是您没有将文本区域添加到框架中。
其他问题是您应该从重写的paint()方法中调用paint(),而不是paintComponent()。
另外,您不应该在 Paint() 方法中读取图像。
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.