• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Scaling

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

I have a JTextPane with some styled text in it and i am trying to scale them.

What i mean is that assuming that the text inside the JTextPane on startup is a 100% in size. After i click some JButton all the font size of the entire document is reduced to 25%

The thing is that this JTextPane contains alot of text that has different font sizes thus i want each of their respective font sizes of the character to be 25% of its original value.

Does anyone know how to do this?

But is there another way i could achieve the scaling of my styled text in my JTextPane so that it is 25% of its original value by means of subclassing my JTextPane or StyledDocument class and overiding its paint method?

Does anyone know how to do this?

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I tried adopting you way and tried to it but the program does not seem to work.

Here is a full compilable example where you can compile the code and see what i mean



The thing is that the text is scaled corretly but ScrollPane screws up completely and the typing of the text is not accurate

Is the way i am scaling the JTextpane correct?

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you are doing with the various 'getXXXSize' methods is changing the size of the
JTextPane which will have an affect on the JScrollPane. In the 'setTransform' call in the
'paint' method you are scaling the entire rendering of the JTextPane by the scale factor.
This is just like taking a photo of it and scaling it: text, borders, scrollBars ...
everything is scaled. The 'paint' method is called to render the JTextPane component.
Setting a transform for its graphics context affects everything in the rendering.

From reading your original question/intent this does not seem to be what you want. I think
you want the JTextPane to appear at its normal size and the font sizes of all styled text
to change by a uniform scale factor. If this is so then I can see two ways of doing this.
The first is to save references to the parent Style objects as you create them and use
these to change the font sizes by your scale factor. I tried to illustrate this in
FontSizeTest.

The second way is to not save any references to the styles you set in the document at
construction. When you are ready for scaling you get the document, enumerate through the
styles in it, identify the ones that have a font size attribute and reset the attribute
with the newly scaled size. This approach is a little more general and flexible than the
first.

Trying to do this inside some kind of paint/rendering code may require some extensive
research into the source code for JTextPane and the plaf classes that it uses for
rendering.
 
Richard West
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,


I think you want the JTextPane to appear at its normal size and the font sizes of all styled text to change by a uniform scale factor.



Yes this exactly what i want to do

The second way is to not save any references to the styles you set in the document at construction. When you are ready for scaling you get the document, enumerate through the styles in it, identify the ones that have a font size attribute and reset the attribute with the newly scaled size.



I think the second way suits most of my needs but if it is of no inconvinience to you could you post a little sample on how to enumenrate through the document and find font size attribute and change i to the scaled value.

I have a little issue that i am also worried about in that the font size attribute take in an integer but when i get the scaling factor it will be a double. Yes i can cast it to an integer but would that not cause a lost of precision that could have huge effects on what i am doing?

I really appreciate that you are taking this time to answer my question
craig wood

Any help is greatly appreciated

Thank You

Yours Sincerely

Richard West
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
reply
    Bookmark Topic Watch Topic
  • New Topic