Menu

#240 Adding JscrollPane to the print preview keeps scrolling

open
nobody
Other (56)
6
2009-11-20
2009-11-12
No

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;

ppc.add(_pagePreview);
JPanel tbCont = new JPanel(new BorderLayout());
JPanel cp = new JPanel(new BorderLayout());
_previewScroll = new JScrollPane(cp);
_previewScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
_previewScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

tbCont.add(_toolBar,BorderLayout.NORTH);
tbCont.add(Box.createVerticalStrut(10),BorderLayout.SOUTH);
tbCont.setBorder(new EmptyBorder(0,0,5,0));

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

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

thanks

Discussion

  • 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?

    Thanks

     
  • Shuaib Zahda

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

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.