Java Swing - Transparent artifact-causing components

I'm currently working on a group project for a college course, and I hit a little stumbling block. The program we decided to implement is a Peer-to-Peer chat client with a central server for storing and sharing usernames, etc. I was assigned a graphical interface.

A friend jokingly suggested that I turn on a "glowing background!". Therefore, I decided to do just that, but have a background image selected by the user. As is, only bits and fragments of the background image will be visible with all components on top of it, so I decided to try to implement transparency.

This is where my problem is:

When sending information from the input window to the chat window or when navigating through the friends list or scrolling through the chat window, strange artifacts are left behind. These artifacts are sometimes translucent β€œghosts” of the Submit button, sometimes part of a menu or old text. It seems to me that the whole frame is not correctly redrawn, but I'm not sure how this works.

For components that implement the JTextComponent, I set their highlight color to be translucent. For other components, I set the background translucent. I have a setTranslucency (Component com) function that looks at a component, sets its translucency depending on what it is, and then sees if it is a container of some type and recursively sets the translucency of each element.

, , , (, ).

,

1) , , ?

,

2) , ? , ?

:

http://i.stack.imgur.com/4J9GJ.png

+3
3

Swing, , . false isOpaque() ( setOpaque(false), isOpaque, - ).

- , . ( .)

: , Swing , , (, JTextField ) . , , (= ), .

+3

myComponent.revalidate();
myComponent.repaint();
, "" , , .

0

JFrame.repaint(). . JFrame, paint() JFrame. , , , paint() GUI. :

  • paint() GUI. repaint().
  • GUI [ JButton, JTextField...], repaint(). Container [JFrame, JPanel...] repaint() .
0

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


All Articles