4

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.
Community
  • 1
  • 1
700 Software
  • 85,281
  • 83
  • 234
  • 341
  • -1, I'm sure I saw this posted yesterday. What happened to the other posting. People don't like spending time repeating suggestions that have already been made. – camickr Jun 16 '11 at 17:01
  • See my edit. I would have posted this information from the start, but I wanted to keep the question short. – 700 Software Jun 16 '11 at 17:27

1 Answers1

5

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.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • It does not work. The background does not show through, and still get screen painting issues when using `jEditorPane.setBackground(new Color(0,0,0,0))`. – 700 Software Jun 16 '11 at 17:14
  • It works fine for me. There is not need to play with transparent background colors. The logic actually makes 3 components non-opaque, the scrollpane, the viewport and the editor pane, so that the background of the panel can be painted properly. – camickr Jun 16 '11 at 18:32
  • 1
    Found it. co-worker was setting non opaque, but did not remove the background color. I failed to set non-opaque of the viewport. I did not realize that viewport was a separate element. We were using setViewportView which was generated by the GUI builder. Don't know why BackgroundPanel did not set it to opaque like you expected it to. – 700 Software Jun 16 '11 at 19:54
  • @George Bailey, actually it is your responsibiltiy to post code that demonstrates the problem. Its called a SSCCE (http://sscce.org ). Most of the time you will find simple mistakes like this when you cut the code down to the bare minimum. – camickr Jun 17 '11 at 01:22
  • Thanks for your help. Sorry for the trouble. – 700 Software Jun 17 '11 at 16:30