File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JScrollBar Not Moving ViewPort Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JScrollBar Not Moving ViewPort" Watch "JScrollBar Not Moving ViewPort" New topic
Author

JScrollBar Not Moving ViewPort

Andrew Cero
Greenhorn

Joined: Mar 02, 2009
Posts: 6
Hello! Im adding a class I created with 2D graphics called AnimationChartCanvas on to my class AnimationChart. After I added the JScrollBar and move the scroller, it doesn't move the viewport. If anyone could please help me out that would be awesome. Im still a newbie at Java programming .

Here is my code so far: (i think I added extra stuff when I tried calling the JScrollPane stuff).. My code displays the actual scrollbar, but the scrollbar doesn't control the view.


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

Please Use Code Tags. You can edit your post to add them.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Andrew Cero
Greenhorn

Joined: Mar 02, 2009
Posts: 6
Updated
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> After I added the JScrollBar and move the scroller, it doesn't move the viewport.

if you're talking about this scrollbar
JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 50, 5, 1000);

why would it do anything? (unless you've not posted some of the code)
Andrew Cero
Greenhorn

Joined: Mar 02, 2009
Posts: 6
I am unfamiliar with the coding for JScrollBar, when the scroll bar moves, do you have to use the actionlistener to get it to move?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
JScrollpanes have their own scrollbars

vbar is just a JScrollbar sitting there doing nothing

if you're not seeing the scrollpane's scrollbar,
chart_canvas probably does not have a preferredSize set

try adding this line
chart_canvas.setPreferredSize(new Dimension(1000,1000));

where 1000,1000 is larger than the size of the frame
Andrew Cero
Greenhorn

Joined: Mar 02, 2009
Posts: 6
Hey! It works perfectly. I guess thats the way of setting the Viewport dimensions. Thank you so much for your help.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JScrollBar Not Moving ViewPort
 
Similar Threads
JScrollBar and JButton display problems
converting into applet
synchronize two ScrollPane
advice on drawing a square wave pulse train
JTextArea not appearing in JDialog