I have a problem with the JTextArea . I wanted to make invisible the JTextArea with setOpaque(false) but it does not work. This is my code:
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);
}
}
I tried this code but does not work. The JTextArea does not become transparent.
你还必须设置scrollPane的视口不透明度:
scrollPane.getViewport().setOpaque(false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.