Share

DrJava

Tracker: Support Requests

6 Adding JscrollPane to the print preview keeps scrolling - ID: 2896887
Last Update: Comment added ( shuaib85 )

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_SCROLLBA
R_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


Shuaib Zahda ( shuaib85 ) - 2009-11-12 22:33

6

Open

None

Nobody/Anonymous

Other

None

Public


Comments ( 2 )




Date: 2009-11-20 23:03
Sender: shuaib85

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


Date: 2009-11-14 05:22
Sender: mgrickenSourceForge.net SubscriberProject AdminAccepting Donations

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.


Log in to comment.

Attached File ( 1 )

Filename Description Download
Screenshot.png Download

Changes ( 2 )

Field Old Value Date By
priority 5 2009-11-20 23:03 shuaib85
File Added 350660: Screenshot.png 2009-11-12 22:33 shuaib85