#240 Adding JscrollPane to the print preview keeps scrolling

Other (56)

HI there, I am adding some functionalities to DrJava, which i will submit later because I am still learning how to do stuff on it.

I have been working on zooming in and zooming out the print preview. I managed to get it working. however, the preview will go beyond the screen so i added a scrollpane in order to keep the preview within the window frame.

I added the scrollpane and when i run it, the scroll pane will keep scrolling without stopping. I tried several way to fix it but i could not do it.

the following is the snippet of code that is modifed in previewframe.java

private JScrollPane _previewScroll;

JPanel tbCont = new JPanel(new BorderLayout());
JPanel cp = new JPanel(new BorderLayout());
_previewScroll = new JScrollPane(cp);

tbCont.setBorder(new EmptyBorder(0,0,5,0));

cp.setBorder(new EmptyBorder(5,5,5,5));
cp.add(tbCont, BorderLayout.NORTH);
cp.add(ppc, BorderLayout.SOUTH);

attached is a screenshot when the pane starts to scroll non stopping

It will be great if you provide me with hints on how to solve this problem



  • Shuaib Zahda

    Shuaib Zahda - 2009-11-12
  • Mathias Ricken

    Mathias Ricken - 2009-11-14

    I believe you need to modify PagePreviewContainer. If you look at

    public Dimension getPreferredSize() { return getParent().getSize(); }

    it gets the size of the parent as preferred size. But if the parent is a scroll pane, then it probably doesn't have a fixed size.

  • Shuaib Zahda

    Shuaib Zahda - 2009-11-20

    Thanks for the information. That was of help to me and I managed to get the zooming functioning.

    I would like to ask about the possibility of making unit test (junit) for the same class. I tried several way to test it but i could not because it is abstract.
    I am trying to test that the buttons are enabled or disabled in the toolbar for example.

    Can you please let me know if it is possible to test such class and if yes. how?


  • Shuaib Zahda

    Shuaib Zahda - 2009-11-20
    • priority: 5 --> 6

Log in to post a comment.