• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Text canvas vertical scroll

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have an application that draws strings of text on a canvas doing word wrapping and breaking whenever necessary. Canvas' height is initially zero and grows as strings are drawn onto it. The final canvas' height is calculated as a last step of the paint() method. Vertical text scrolling has to be implemented as well, for which purpose I'm using ScrollPane. I'm experiencing one problem here: it looks like I cannot dynamically set the canvas' height by the time all strings have been drawn on it. The getPreferredSize() method is called by the layout manager when the canvas class is instantiated and overriding the method doesn't help much.
The only way to make scrolling work is to resize the application frame as soon as it's created at least one pixel in any direction. Then apparently the getPreferredSize() method is called again and the updated canvas' size is set.
Using setSize() explicitly doesn't help for some reason...
Resizing the frame seems to fire some hidden underlying mechanism which sets the updated size of the canvas and let the scrolling work perfectly...
Another way to make it work is to set preferred size to a constant value, eg.


Both workarounds are obviously very weird and cannot be used seriously.

I'm totally stuck here, tried hundreds of different tricks, but still can't help it...

Anybody ever experienced something like this?

P.S. Main app frame class extends Frame, text canvas class extends Canvas. Default layout manager (BorderLayout) is used to layout the ScrollPane with text canvas.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Dmitry Danilov
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow!..
This has to be digested...
Thanks a lot for the reply, Craig!
 
What I don't understand is how they changed the earth's orbit to fit the metric calendar. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic