JPanel transparency issue

I have a dark gray JPanel with JLabel on it. I set new Color(0, 0, 0, .5f) (tranparent) as the JLabel background, and change the text several times with the button. The problem is that every time the text changes, the previous text still remains with the new text. I am changing the text from “123456789” to “1234567”, “12345” and “123”. Here is a screenshot:

alt text

How do I get rid of this "shadow"?

+4
source share
3 answers

Check out Backgrounds With Transparency for an explanation and possible solution.

And in the future, the SSCCE post demonstrates the problem, not the image.

+5
source

This example also makes a translucent JPanel .

+3
source

try, maybe this will solve your problem: In actionPeroformed ..

 public void actionPerformed(ActionEvent e) { final JLabel tmpLabel = new JLabel(value[++i]); //change text label.setFont(new Font("Times New Roman", 1, 36)); label.setForeground(new Color(255, 255, 255)); label.setBackground(new Color(0, 0, 0, .5f)); label.setHorizontalAlignment(SwingConstants.CENTER); label.setOpaque(true); label.setBounds(10, 10, 270, 70); label = tmpLabel; //replace the entire label with a new label } 
+2
source

Source: https://habr.com/ru/post/1334161/


All Articles