Scaling


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Scaling

Hybrid View

  1. #1
    Join Date
    Oct 2004
    Posts
    151

    Question Scaling

    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
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

  2. #2
    Join Date
    Oct 2004
    Posts
    151

    Question

    Hi everyone,

    I tried to do the scaling of the JtextPane and i seem to get weird results and i really don't know why this is so and maybe someone could weigh in

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

    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
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

  3. #3
    Join Date
    Oct 2004
    Posts
    151
    Hi everyone,

    No one knows this?

    Richard West
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

Similar Threads

  1. Scaling enterprise apps down...
    By Steve in forum Java
    Replies: 2
    Last Post: 01-10-2003, 02:18 PM
  2. exchange 2000 scaling
    By dave in forum Enterprise
    Replies: 0
    Last Post: 10-25-2001, 04:09 PM
  3. Scaling problems using API Graphics
    By Allen Johnson in forum VB Classic
    Replies: 2
    Last Post: 04-28-2000, 12:00 PM
  4. Scaling problems using API Graphics
    By Allen Johnson in forum VB Classic
    Replies: 0
    Last Post: 04-26-2000, 01:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center