简体   繁体   中英

JScrollBar thumb position (value) won't change

I have a JScrollPane jScrollPane2 . i tried to change the position (value) of the thumb, but its position doesn't change, here's the code :

public AfficherArbreSyntaxique() {
        initComponents();

        jPanelPourDessinerArbre1.setMinimumSize(new Dimension(10000, 10000));
        jPanelPourDessinerArbre1.setPreferredSize(new Dimension(10000, 10000));
        ;
        //        jPanelPourDessinerArbre1.s //ensureIndexIsVisible
        // jPanelPourDessinerArbre1.repaint();


        jScrollPane2.getVerticalScrollBar().setValueIsAdjusting(true);
        jScrollPane2.getHorizontalScrollBar().getModel().setValue(10);

        this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);

    }

What is the problem and how to solve it ?

I would guess the GUI is not visible yet so components don't have a size yet.

Try setting the value AFTER the frame is visible. One way to do this is to wrap the code is a SwingUtilities.invokeLater().

SwingUtilities.invokeLater(new Runnable()
{
    public void run()
    {
        jScrollPane2.getHorizontalScrollBar().getModel().setValue(10);
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM