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:

B4X:
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?
 

Daestrum

Expert
Licensed User
Longtime User
Not tried it but the following code 'may' do the same
Requires JavaObject Library
B4X:
...
Dim jo As JavaObject = yourscrollpane
jo.RunMethod("setCache",array(False))
...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

nobbi59

Active Member
Licensed User
Longtime User
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

nobbi59

Active Member
Licensed User
Longtime User
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
Top