How to access the Scrollbars of a ScrollPane

后端 未结 3 1749
旧巷少年郎
旧巷少年郎 2021-01-01 01:02

I\'m trying to get some information about the ScrollBar components that are by standard included in a ScrollPane. Especially i\'m interested in rea

3条回答
  •  一向
    一向 (楼主)
    2021-01-01 01:16

    This not is the best pratice, but works,

    private boolean determineVerticalSBVisible(final ScrollPane scrollPane) {
        try {
            final ScrollPaneSkin skin = (ScrollPaneSkin) scrollPane.getSkin();
            final Field field = skin.getClass().getDeclaredField("vsb");
            field.setAccessible(true);
            final ScrollBar scrollBar = (ScrollBar) field.get(skin);
            field.setAccessible(false);
            return scrollBar.isVisible();
        } catch (final Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    

    Use "hsb" for Horizontal ScrollBar.

    Best Regards, Henrique Guedes.

提交回复
热议问题