3

I want to scale the JTextPane for inline text editing. User can zoom/pan the text and double click on a JLabel to edit it. The editor should scale to the current zoom level.

I extended JTextPane and painted by scaling the component graphics. However editing does not work at scale different than 1.

How to scale a editable JTextPane?

Any solutions/pointers would be helpful. Thanks in advance.

I do not find the related question useful.

Following only scales the component and paints at different scale. However editing is not scaled.

public class ScaledJTextPane extends JTextPane {

      private double scale = 0;

      public ScaledJTextPane () {
        this.scale = 1;
      }

      protected void paintComponent(Graphics g) {
        Graphics2D g2 = null;        
        g2 = (Graphics2D) g;
        g2.scale(this.scale, this.scale);

        super.paintComponent(g2);
      }

      public double getScale() {
        return this.scale;
      }

      public boolean setScale(double xscale) {
        boolean status = true;        
        status = (xscale != 0.0 && xscale != Float.NaN);
        if (status) this.scale = xscale;

        return status;
      }      
    }
Community
  • 1
  • 1
18bytes
  • 5,951
  • 7
  • 42
  • 69
  • 2
    what did you found, please post here (edit your post) rellated code that shows what ..., please http://sscce.org/, may be trivial mistake – mKorbel Sep 19 '11 at 16:16
  • Problem I face is exactly the same mentioned in the [link] (http://coding.derkeiler.com/Archive/Java/comp.lang.java.gui/2004-08/0449.html) – 18bytes Sep 19 '11 at 16:34
  • If you add `public void repaint( int x, int y, int width, int height ) { super.repaint(0, 0, getWidth(), getHeight()); }` It almost fix the problem, but I don't know how to fix double to int in the repaint. – francogp Dec 04 '18 at 07:48

0 Answers0