Moving JScrollPane horizontally results in blured text
Asked Answered
O

3

5

I have a TextArea inside JScrollPane inside standard JPanel.

    JPanel panelMain = new JPanel();
    panelMain.setBorder(titledBorder1);
    panelMain.setBounds(new Rectangle(2, 5, 970, 700));
    panelMain.setLayout(null);

    JTextArea fieldBody = new JTextArea();
    JScrollPane fieldBodyScrollPane = new JScrollPane(fieldBody);
    fieldBodyScrollPane.setBounds(70, 140, 790, 500);
    panelMain.add(fieldBodyScrollPane);

When I type enough text in a single row the horizontal knob appears - so far good. But when I start moving the knob left and right, the text gets blured (see image). Interestingly, nothing weird happens when I move the textarea up and down.

blured text in jscrollpane when scrolling horizontally

I use Ubuntu 12.04 with Unity. This graphic artifact never appeared to me before. Any hints what could be the problem?

Oread answered 8/10, 2012 at 11:52 Comment(2)
1) fieldBodyScrollPane.setBounds(70, 140, 790, 500); Is likely indicative of the root of the problem. Use layouts. 2) For better help sooner, post an SSCCE.Tobit
try to test with myJViewPort.setScrollMode(JViewport.BLIT_SCROLL_MODE); and/or myJViewPort.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); and/or myJViewPort.setScrollMode(JViewport.SIMPLE_SCROLL_MODE); and/or ???Hagfish
T
4
import java.awt.GridLayout;
import javax.swing.*;
import javax.swing.border.*;

public class CaseForLayoutsNumber547 {

    CaseForLayoutsNumber547() {
        Border titledBorder1 = new TitledBorder("Case for Layouts #547");
        // START: code snippet variant
        JPanel panelMain = new JPanel(new GridLayout());
        panelMain.setBorder(titledBorder1);

        JTextArea fieldBody = new JTextArea(5,40);
        JScrollPane fieldBodyScrollPane = new JScrollPane(fieldBody);
        panelMain.add(fieldBodyScrollPane);
        // END: code snippet variant
        JOptionPane.showMessageDialog(null, panelMain);
    }

    public static void main(String[] args) {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                new CaseForLayoutsNumber547();
            }
        };
        SwingUtilities.invokeLater(r);
    }
}

I do not see any scroll artifacts in this SSCCE. Do you?

Tobit answered 8/10, 2012 at 12:13 Comment(0)
A
2

Here's @Andrew's SSCCE displaying itself; it looks the same with either Ambience or Radiance.

image

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.1 LTS
Release:    12.04
Codename:   precise
$ java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.4) (6b24-1.11.4-1ubuntu0.12.04.1)
OpenJDK Client VM (build 20.0-b12, mixed mode, sharing)

Addendum: Looking closer at your screenshot, failing to honor the opacity property can cause such rendering artifact, and the default setting may vary among Look & Feel implementations.

Armistice answered 8/10, 2012 at 18:4 Comment(1)
+1, now we can say that of the tags, only 'visual-artifacts' is not relevant to your answer. :)Tobit
J
2

This problem happens in OpenJDK (6 and 7, at least; and at least on Linux), and does not happen in Oracle Java 6 and 7 (on Linux).

The workaround suggested by mKorbel works for me:

scrollPane.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);

So I guess it's a bug in OpenJDK.

Jannet answered 17/4, 2013 at 23:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.