0

I have made a custom Table Component in Java and I am curious why scrollRectToVisible always scrolls to bottom right point of the input rectangle.

Is there a way how to tell parent component to attempt to view whole rectangle? Because its not funny when you want to automatically scroll to a table row and it always just view bottom of the wanted table row.

*EDIT

private JPanel box = new JPanel();
private JScrollPane scroll = new JScrollPane(box, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
public void scrollTo(int index){
    if(datas.size() != 0){
        JPanel panel;
        if(index < 0){
            index = 0;
        }else if(index >= datas.size()){
            index = datas.size() - 1;
        }
        panel = datas.get(index);
        Rectangle rectangle = panel.getBounds();
        if(index != 0){
            rectangle.setLocation(0, rectangle.y + 1);
        }
        box.scrollRectToVisible(rectangle);
    }
}
  • Please show what code you have written, it helps. – CaptJak Aug 30 '15 at 13:46
  • @CaptJak not sure where is exactly the problem in my program so I cant show you correct problem. Also my Component has over 400 lines of code. But if you would want to see what method is scrolling it all then check my edited question. – Martin Krajčírovič Aug 30 '15 at 14:29

1 Answers1

0

*SOLUTION
Oh well, never mind I found out the problem. It was scrolling to bottom right corner because for some reason during constructor was getVisibleRect telling all data are zero, but after a whole Frame was constructed then it started to scrolling to normal position :(