Search code examples
javalibgdx

LibGDX Change my ScrollPane's startposition


My scrollpane is fully working if you want to scroll from top to bottom. My problem is when I call a setScreen command I want my camera/screen to start at a specific section on the scrollpane, for example at

table.add(menuButton1).row();

Or at the bottom of my ScrollPane. I have read through the Libgdx ScrollPane document, but I can't find a solution to my problem.

My scrollpane at the moment:

  camera = new OrthographicCamera(500,600);
    stage.getHeight();
    stage.getWidth();
   extendViewport =new ExtendViewport(500,1500, camera);
    stage=new Stage(extendViewport);

    Table scrollableTable = new Table();
    scrollableTable.setFillParent(true);
    stage.addActor(scrollableTable);

    Table table = new Table();
    table.add(label2).spaceBottom(1200).row();

    //table.add(smile).spaceBottom(2300).row();
    table.add(label).spaceBottom(2300).row();
    table.add(menuButton1).row();
    //table.add(topbutton).spaceBottom(2300).row();
    table.add(label3).spaceBottom(2300).row();


    table.pack();
    table.setTransform(true);  //clipping enabled

    stage.setDebugAll(true);
    table.setOrigin(table.getWidth()/2,table.getHeight()/2);
    // table.setScale(.5f);

    final ScrollPane scroll = new ScrollPane(table);
    scrollableTable.add(scroll).expand().fill();
    Gdx.input.setInputProcessor(stage);

Solution

  • ScrollPane.scrollTo works well, but as you use a table, you need to validate ScrollPane before calling it.