失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > java框体怎么添加背景图 文本框添加背景图片 文本框背景图片 public class

java框体怎么添加背景图 文本框添加背景图片 文本框背景图片 public class

时间:2024-06-14 08:39:19

相关推荐

java框体怎么添加背景图 文本框添加背景图片 文本框背景图片 public class

文本框添加背景图片,文本框背景图片,public classpublic class WatermarkTextField extends JTextField { BufferedImage img; TexturePaint texture; public WatermarkTextField(File file) throws IOException { super(); img = ImageIO.read(file); Rectangle rect = new Rectangle(0,0, img.getWidth(null),img.getHeight(null)); texture = new TexturePaint(img, rect); setOpaque(false); } } public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D)g; g2.setPaint(texture); g.fillRect(0,0,getWidth(),getHeight()); super.paintComponent(g); } public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Watermark JTextField Hack"); JTextField textfield = new WatermarkTextField(new File("red.png")); textfield.setText("A Text Field");frame.getContentPane().add(textfield); frame.pack(); frame.show(); }//该片段来自于

如果觉得《java框体怎么添加背景图 文本框添加背景图片 文本框背景图片 public class》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。