gpt4 book ai didi

java - JTextArea画Java?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:00:38 26 4
gpt4 key购买 nike

这是代码。不知道为什么文本区域不显示背景图像

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

}
}

这是完整的代码。任何帮助都会被淘汰

谢谢,技术中心

最佳答案

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

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

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

关于java - JTextArea画Java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7343336/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com