B4J Question Blurry ScrollPane Content

nobbi59

Active Member
Licensed User
Longtime User
Hello all,

Im having an issue with a ScrollPane. I add the ScrollPane by code and also add its content by code.

The content becomes blurry, a big problem especially with text.

So I googled a bit and found the solution for this. First I tried it with Integer-only positioning values but this didnt work. Then I found a Java Code for fixing this:

Code:
import com.sun.javafx.scene.control.skin.ScrollPaneSkin;
import java.lang.reflect.Field;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.StackPane;

public class FieldUtils {

    public static void fixBlurryText(Node node) {
        try {
            Field field = ScrollPaneSkin.class.getDeclaredField("viewRect");
            field.setAccessible(true);

            ScrollPane scrollPane = (ScrollPane) node.lookup(".scroll-pane");

            StackPane stackPane = (StackPane) field.get(scrollPane.getSkin());
            stackPane.setCache(false);

        } catch (NoSuchFieldException | SecurityException |  IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}

The forum user that posted this code commented this code with:

I checked the internal skin code and found a workaround, not pretty though. The problem is inside com.sun.javafx.scene.control.skin.ScrollPaneSkin, which calls viewRect.setCache(true). Disabling cache appears to solve the problem.

I dont know anything about Java. Can somebody help me that I can use this code inside B4J?
 
Not tried it but the following code 'may' do the same
Requires JavaObject Library
Code:
...
Dim jo As JavaObject = yourscrollpane
jo.RunMethod("setCache",array(False))
...
 
Upvote 0
I add the ScrollPane by code and also add its content by code.
This is a mistake in most cases.

Does the text get blurred in this example: https://www.b4x.com/android/forum/t...listview-cross-platform-customlistview.84501/ ?

The code above requires jReflection as it accesses private fields.
Code:
Dim jo As JavaObject = yourscrollpane
Dim r As Reflector
r.Target = jo.RunMethod("getSkin", Null)
jo = r.GetField("viewRect")
jo.RunMethod("setCache", Arrary(False))
 
Upvote 0
Thanks @Daestrum, tried it but it didnt work.

@Erel it doesnt become blurry in your example. I tried your code but this doesnt help. The solution provided doesnt seem to be the one that fixes it in my case. Do you have any other suggestions?
 
Upvote 0
That seems very crazy. My fisrt guess was the positioning with non-integer values, I tried to round the values but this doesnt seem to fix it.
 
Upvote 0
Back
Top