[英]setOpaque(false) not work with JTextArea
我有一个JTextArea的问题。 我想用setOpaque(false)使JTextArea不可见,但它不起作用。 这是我的代码:
public class NewClass extends JFrame {
private JPanel panel;
private JTextArea tA;
private JScrollPane scrollPane;
public NewClass() {
this.setTitle("Test");
initJpanel();
initTextArea();
this.setSize(800, 640);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(panel);
this.setVisible(true);
}
public static void main(String[] args) {
new NewClass();
}
private void initJpanel() {
panel = new JPanel();
panel.setLayout(null);
panel.setDoubleBuffered(true);
panel.setSize(800, 640);
panel.setLocation(0, 0);
panel.setBackground(Color.red);
}
private void initTextArea() {
tA= new JTextArea();
tA.setOpaque(false);
tA.setLineWrap(true);
tA.setWrapStyleWord(true);
tA.setSize(400, 100);
tA.setLocation(0, 0);
tA.setOpaque(false);
//tA.setBackground(new Color(0, 0, 0, 90));
scrollPane = new JScrollPane(tA);
scrollPane.setSize(400, 100);
scrollPane.setLocation(0, 0);
scrollPane.setOpaque(false);
//scrollPane.setBackground(new Color(0, 0, 0, 90));
scrollPane.setVisible(true);
panel.add(scrollPane);
}
}
我试过这段代码但是没有用。 JTextArea不会变得透明。
你还必须设置scrollPane的视口不透明度:
scrollPane.getViewport().setOpaque(false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.