JTextArea 添加背景图片之后文字不显示

不才 2010-04-23 03:01:25
如题

backimage = new BackImage();
imgBackground=new ImageIcon("image/psptxs118.jpg");
noticePanel = new JPanel();
noticePanel.setLayout(null);

noticeta = new JTextArea(noticestr);

noticeta.setLineWrap(true);
noticeta.setEditable(false);
noticeta.setSize(430,110);
noticeta.setLocation(20,20);
backimage.setBackTextArea(noticeta, imgBackground);//就是这行
// noticePanel.setBackground(Color.WHITE);
// noticeta.setBackground(Color.WHITE);
noticeta.setFont(new Font("notice",Font.BOLD,15));
noticePanel.add(noticeta);


BackImage类

void setBackTextArea(JTextArea textarea,ImageIcon imgBackground){
this.textarea=textarea;
this.imgBackground=imgBackground;
textarea.setOpaque(false);
JLabel background=new JLabel(imgBackground);
textarea.add(background,new Integer(Integer.MIN_VALUE));
background.setBounds(0,0,imgBackground.getIconWidth(), imgBackground.getIconHeight());
}


为什么我添加了backimage.setBackTextArea(noticeta, imgBackground)这行之后就不显示文字了呢?请问怎么解决或者怎么使文字显示最高层呢?
...全文
401 5 打赏 收藏 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
不才 2010-04-23
  • 打赏
  • 举报
回复
有没有具体解决的代码呢?
huntor 2010-04-23
  • 打赏
  • 举报
回复
看Swing Hacks,上面有
canoe982 2010-04-23
  • 打赏
  • 举报
回复
JLabel background=new JLabel(imgBackground);
textarea.add(background,new Integer(Integer.MIN_VALUE));

以上代码表明你在textarea添加了一个JLabel,而不是设置了背景图片。这种处理方式应该是不行的。

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧