问题
If I move the JScrollPane so it is in front of and partially covering the JPanel, then the JEditorPane inside of the JScrollPane has paint issues. It does not properly re-paint the JPanel's background. So you end up with screen painting issues when you scroll.
I have tried the overlap using the following methods - JScrollPane inside of JPanel - JScrollPane partially covering JPanel using FreeLayout (NetBeans GUI Builder) - JScrollPane partially covering JPanel using JLayeredPane
The JPanel has a solid background right now, but I will extend it to have a gradient as soon as I get solid background to work.
How can I get the JEditorPane to bring in the cropped background from the JPanel?
I am making it transparent using jEditorPane.setBackground(new Color(0,0,0,0))
I tried using setOpaque(false)
like you would do for a panel, but that just seems to put back a default background if you do it to JEditorPane.
Original question by a co-worker: https://stackoverflow.com/questions/6364460/jframe-screen-paint-issues-when-using-transparency
The original question was not as well written and did not seem to bring good answers.
Responses to co-worker question suggestions:
- "Try with setOpaque(false); instead of setBackground(new Color(0,0,0,0));" did not solve the problem.
- "try adding validate () after the pack()" did not solve the problem.
- "paint your background image on the JViewport" would not work because the background needs to extend beyond the JScrollView and also spread behind other components
- "modify the graphics composite in the UI delegate's paint()" If this will solve the problem, I would like to know how to do it.
回答1:
The Background Panel class has code that attempts to make all component non-opaque so the background will show through.
Edit:
If you want to play with transparent background then you can check out Backgrounds With Transparency for an explanation of the problem and a couple of solutions.
In this case the BackgroundPane is the easier solution.
来源:https://stackoverflow.com/questions/6375198/transparent-jeditorpane-in-a-jscrollpane-over-a-background-jpanel