
Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Hi everyone,
I think you guys have misunderstood my question in that i am
not talking about scaling for printing but something of a zoom in and zoom
out for the JTextPane
Here is a full compilable example where you guys can compile the code and
see what i mean first hand
[code]
import java.awt.*;
import java.util.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.text.*;
public class 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;
public void 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);
}
public static void main(String args[])
{
JTextScalar a = new JTextScalar();
a.initialize();
}
}
class JScalableTextPane extends 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);
}
*/
public void 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
zero - 11 Oct 2005 13:46 GMT
> Hi everyone,
>
[quoted text clipped - 5 lines]
> Here is a full compilable example where you guys can compile the code
> and see what i mean first hand
<snipped>
this is very specific to Swing GUIs, so I think you may have better luck in
either comp.lang.java.gui, or sun's own swing forum at
http://forums.java.sun.com/forum.jspa?forumID=57
Roedy Green - 13 Oct 2005 05:43 GMT
>Graphics2D g2d = (Graphics2D)g;
> g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
[quoted text clipped - 4 lines]
> g2d.setTransform(old);
> super.paint(g2d);
this code here should read:
Graphics2D g2d = (Graphics2D)g;
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
RenderingHints.VALUE_FRACTIONALMETRICS_ON);
AffineTransform old = g2d.getTransform();
g2d.scale(0.5,0.5);
super.paint(g2d);
g2d.setTransform(old);

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Roedy Green - 13 Oct 2005 05:45 GMT
> public void paint(Graphics g)
> {
[quoted text clipped - 7 lines]
> super.paint(g2d);
> }
because you are using Swing, you should be overriding paintComponent,
not paint.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.