If you enter Japanese into JTextArea with JFrame transparent, the frame will turn white.
Once it turns white, it remains white unless it is redisplayed.Does anyone know how to avoid this phenomenon?
public static void main(String[]args){
JFrame frame = new JFrame();
frame.setSize(670,500);
frame.setLocation(600,420);
frame.setUndecorated(true);
frame.setBackground(new Color(0x00000000, true));
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
JTextArea text=new JTextArea();
text.setBackground (Color.RED);
text.setBounds (85, 120, 265, 240);
JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setLayout(null);
panel.add(text);
Container content=frame.getContentPane();
content.add(panel);
frame.setVisible(true);
}
environment:windows7java8
java
There was a similar question and answer in my home SO.
According to the answer, it seems to be caused by a bug in the DirectDraw pipeline in Swing.
By disabling DirectDraw rendering, we avoided the problem.
public static void main(String[]args){
System.setProperty("sun.java2d.noddraw", "true"); // Add this line
JFrame frame = new JFrame(); // Same as below
// Omitted
}
The above is a quick fix.
If you want to disable DirectDraw for individual JTextArea
, see your SO answer to inherit JTextArea
and override paintComponent
.
© 2024 OneMinuteCode. All rights reserved.