【发布时间】:2016-10-18 17:15:23
【问题描述】:
我正在编写一个聊天程序,并试图通过向主 JPanel(构建所有内容的 JPanel)添加背景图像来使其更有趣。当我尝试使用代码将 JTextField 或 JTextArea 的透明度更改为 50% 时
MainPanel = new JPanel(){
@Override
public void paintComponent(Graphics g) {
ImageIcon im = new ImageIcon("background.jpg");
Image i = im.getImage();
g.drawImage(i,0,0,this.getSize().width,this.getSize().height,this);
}
};
...
outputWindow.setBackground(new Color(0,0,0,128));
其中'outputWindow' 是添加到'MainPanel' 的JTextArea,一旦我在该区域中显示一些文本,就会出现很多乱码。 Screenshot of the problem
我按顺序输入了“hi”和“hello world”,你可以在输出屏幕的顶部看到,但是有什么办法可以消除多余的乱码吗?
【问题讨论】:
标签: java swing user-interface background transparency