【发布时间】:2018-06-21 12:29:24
【问题描述】:
我正在尝试用 JScrollPane 包装 JTextPane,我需要背景是透明的。
这是我的代码:
public CharPanel(){
super.setLayout(null);
JButton LButton = new JButton("<");
LButton.setBounds(0, 300, 50, 50);
super.add(LButton);
JButton RButton = new JButton(">");
RButton.setBounds(950, 300, 50, 50);
super.add(RButton);
JTextPane Bio = new JTextPane();
Bio.setBackground(new Color(0, 0, 0, 0));
JScrollPane BioScroll = new JScrollPane(Bio);
BioScroll.setBackground(new Color(0, 0, 0, 0));
BioScroll.setBounds(0, 500, 1000, 150);
super.add(BioScroll);
}
这是正常的样子:https://gyazo.com/db7e4d2a5668b36ffc617cefb1423fc4
这是我输入字符后的样子:https://gyazo.com/1509d952005195d6e14365f0ae2da69a
看到奇怪的视觉错误了吗?
【问题讨论】:
-
请遵循Java命名约定,变量/属性/方法必须以小写字母开头
-
哦,谢谢你的帮助!
-
1) 为了尽快获得更好的帮助,请发帖 minimal reproducible example 或 Short, Self Contained, Correct Example。 2) Java GUI 必须在不同的语言环境中使用不同的 PLAF 在不同的操作系统、屏幕尺寸、屏幕分辨率等上工作。因此,它们不利于像素完美布局。而是使用布局管理器,或combinations of them 以及white space 的布局填充和边框。 3) Swing 不能很好地处理透明组件。
标签: java swing transparency jscrollpane jtextpane