• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JScrollBar Not Moving ViewPort  RSS feed

 
Andrew Cero
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21745
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags. You can edit your post to add them.
 
Andrew Cero
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Updated
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey! It works perfectly. I guess thats the way of setting the Viewport dimensions. Thank you so much for your help.

 
On top of spaghetti all covered in cheese, there was this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!