2

I have a transparency/scrolling problem with my scroll pane. As far as I can tell, the docs do not address this behavior.

Here's is the code for my transparent text pane:

    textArea.setOpaque(false);
    scrollPane.setViewportView(textArea);
    scrollPane.setViewportBorder(border);
    scrollPane.setOpaque(false);
    //scrollPane.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
    scrollPane.getViewport().setOpaque(false);

This works fine, except the scrolling is very sluggish. When the setScrollMode line is uncommented, the scrolling is much more responsive but the transparency is lost.

Is there any way I can get into a win-win situation?

EDIT: Okay, the original question isn't really answered, but I did find out that the cause was actually a call to javax.swing.UIManager.put("TabbedPane.font", someCustomFont). I left out this detail because I thought it was irrelevant.. who would have thought. I don't know why this results in sluggish scrolling, but I'm just glad to have found the problem.

Whired
  • 259
  • 1
  • 11

1 Answers1

1

1) JViewport is by default traslucent/transparent,

2) required set follows methods for JViewpot

JViewport.setScrollMode(JViewport.BLIT_SCROLL_MODE);
JViewport.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
JViewport.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);

3) simple example here, without any freeeze or jumping during the scrolling

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 1) Not from my findings? If I don't call `scrollPane.getViewport().setOpaque(false)`, the whole thing is messed up? 2/3) Wouldn't calling all three at once just result in the last one called being used? – Whired Jan 18 '12 at 19:00
  • important is there, what's Object did you put to the JViewport or JTextArea, – mKorbel Jan 18 '12 at 19:35
  • The view is only a simple default 600x500 JTextPane with 2 full views of text. I am not overriding the paint method of the viewport and I have no need to. I do not have an explanation for the behavior, and wouldn't mind one compared to answers with code similar to that shown in my question. – Whired Jan 18 '12 at 19:54
  • I've posted one. In the example, you might be able to see that when you drag the scrollbar thumb, it's very sluggish. This gets worse when more text is added. When the scroll mode is changed, the sluggishness abates, but the viewport (guessing) is no longer transparent. – Whired Jan 18 '12 at 20:21
  • these methods are for Object added to the JViewport, really never need to solved that why one of them (if is alone) freeze JScrollPane's content not what's and for why sombody implements for JTable `Draws viewport contents into an offscreen image.` simple doesn't works for JTextArea – mKorbel Jan 18 '12 at 20:43