Scaling

Hi everyone,

I have been trying to do the scaling of a JTextPane but i seem to be geeting weird results and i don't know why and hope someone could really weigh on this

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

import java.awt.*;

import java.util.*;

import java.awt.geom.*;

import javax.swing.*;

import javax.swing.text.*;

publicclass JTextScalar

{

JFrame fr =new JFrame ("Frame");

JScalableTextPane TextPane1 =new JScalableTextPane();

StyleContext sc =new StyleContext();

DefaultStyledDocument dse =new DefaultStyledDocument(sc);

JScrollPane ScrollPane1 =new JScrollPane(TextPane1, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,

ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

StyledEditorKit StyledEditorKit1 =new StyledEditorKit();

JViewport viewport;

publicvoid initialize()

{

Container pane = fr.getContentPane();

pane.setLayout(new BorderLayout());

fr.setSize(250,300);

fr.setLocation(300,300);

fr.setBackground(Color.lightGray);

dse.putProperty("i18n", Boolean.TRUE);

TextPane1.setEditorKit(StyledEditorKit1);

//The below command line sets the document that the JTextPane will be

//be referencing to

TextPane1.setDocument(dse);

viewport =new JViewport();

viewport.setView(TextPane1);

viewport.setScrollMode(viewport.SIMPLE_SCROLL_MODE);

//viewport.setScrollMode(viewport.BACKINGSTORE_SCROLL_MODE);

ScrollPane1.setViewport(viewport);

pane.add("Center", ScrollPane1);

//ScrollPane1.invalidate();

ScrollPane1.revalidate();

ScrollPane1.repaint();

TextPane1.revalidate();

TextPane1.repaint();

fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

fr.pack();

fr.setVisible(true);

}

publicstaticvoid main(String args[])

{

JTextScalar a =new JTextScalar();

a.initialize();

}

}

class JScalableTextPaneextends JTextPane

{

/*

public void paintComponent(Graphics g)

{

//This function overrides the JPanel paintComponent function

//and paints the buffered image on the JPEGPanel

Graphics2D g2d = (Graphics2D)g;

g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,

RenderingHints.VALUE_FRACTIONALMETRICS_ON);

g2d.scale(0.5, 0.5);

//AffineTransform old = g2d.getTransform();

//g2d.setTransform(old);

//super.notify();

//super.revalidate();

//super.repaint();

super.paintComponent(g2d);

}

*/

publicvoid paint(Graphics g)

{

Graphics2D g2d = (Graphics2D)g;

g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,

RenderingHints.VALUE_FRACTIONALMETRICS_ON);

g2d.scale(0.5,0.5);

AffineTransform old = g2d.getTransform();

g2d.setTransform(old);

super.paint(g2d);

}

public Dimension getPreferredSize()

{

Dimension d= super.getPreferredSize();

d.setSize(d.width*0.5,d.height*0.5);

return d;

}

public Dimension getMinimumSize ()

{

Dimension d= super.getMinimumSize ();

d.setSize(d.width*0.5,d.height*0.5);

return d;

}

public Dimension getMaximumSize ()

{

Dimension d= super.getMaximumSize();

d.setSize(d.width*0.5,d.height*0.5);

return d;

}

public Dimension getSize ()

{

Dimension d= super.getSize ();

d.setSize(d.width*0.5,d.height*0.5);

return d;

}

}

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

[5752 byte] By [] at [2007-10-2 2:05:52]
# 1
Hi everyone, No one knows this? Could it be that i am using the wrong alogaritm to scale my JTextPane?Richard West
at 2007-7-15 19:47:18 > top of Java-index,Desktop,Core GUI APIs...
# 2
I suggest you read the answer Roedy gave you on Usenet.
dcmintera at 2007-7-15 19:47:18 > top of Java-index,Desktop,Core GUI APIs...
# 3
Hi everyone,> I suggest you read the answer Roedy gave you on> Usenet.I used Roedy's answer but its still not working and i seaving through the code to see if there's something i missedRichard West
dcmintera at 2007-7-15 19:47:18 > top of Java-index,Desktop,Core GUI APIs...
# 4
HI everyone, NO one know how to scale a JTextComponent?Richard West
dcmintera at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 5
> HI everyone,> > NO one know how to scale a> NO one know how to scale a JTextComponent?> > Richard WestNO one cares to answer you, you mindless twit.
warnerjaa at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 6
> NO one cares to answer you, you mindless twit.Stop hijacking my thread woldie. Go back to smucksvilleThis is the Swing forum. Either act as an adult or ship outRichard West
warnerjaa at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 7
Hi everyone,Hijacking is not good.Prickie Less
freesoft_2005.a at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 8
Josah aka freesoft_2005 can you stop hijacking my threads and stop this nonsense.Richard West
freesoft_2005.a at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 9
> Josah aka freesoft_2005 can you stop hijacking my> threads and stop this nonsense.> > Richard WestRichard,Jos would not do this! You have to find someone else to blame!Sabre
sabre150a at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 10

> Jos would not do this! You have to find someone else

> to blame!

>

> Sabre

He once made specific threats to me about doing this to the so called trolls by hijacking their threads by using variations of their usernames so one will naturally assume its him.

Sabre see the ssl thread in the socket forum.

You apparently don't know jos as well as you think. I don't go around blaming people unless i know for a certain fact its him

Richard West

sabre150a at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 11

>

> Sabre see the ssl thread in the socket forum.

> You apparently don't know jos as well as you think. I

> don't go around blaming people unless i know for a

> certain fact its him

I know for a fact that it is not Jos or me. I can't say that about any of the other regular posters.

sabre150a at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 12
Hi everyone,> I know for a fact that it is not Jos or me. I know its not you as you won't stoop so low but how can you be so sure about jos. Care to share.Richard West
sabre150a at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 13
> Care to share.Not really!
sabre150a at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 14
> > Care to share.> > Not really!So you don't really know that the guy is no jos do you. Well unless you are jos which i really hope you are notRichard West
sabre150a at 2007-7-15 19:47:19 > top of Java-index,Desktop,Core GUI APIs...
# 15

> > > Care to share.

> >

> > Not really!

>

> So you don't really know that the guy is no jos do

> you. Well unless you are jos which i really hope you

> are not

Are you trying to pick a fight again? I don't care whether or not you believe me!

sabre150a at 2007-7-20 17:25:07 > top of Java-index,Desktop,Core GUI APIs...
# 16
>I don't care> whether or not you believe me!Then why post in this thread in the first place. No one is trying to pick a fight with you but simply having a resonable conversation with youRichard West
sabre150a at 2007-7-20 17:25:07 > top of Java-index,Desktop,Core GUI APIs...
# 17

> >I don't care

> > whether or not you believe me!

>

> Then why post in this thread in the first place. No

> one is trying to pick a fight with you but simply

> having a resonable conversation with you

In post 8 you accused Jos of being the imposter. In post 9 I indicated that I did not believe that Jos is the imposter. I was just defending my friend.

You choose not to believe Jos or me. Now others reading this thread will at least be able to make up their mind and not just have your unfounded accusations to go on.

sabre150a at 2007-7-20 17:25:07 > top of Java-index,Desktop,Core GUI APIs...