开发者

Scaling editable JTextPane

开发者 https://www.devze.com 2023-04-06 10:11 出处:网络
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 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 != Fl开发者_StackOverflow中文版oat.NaN);
        if (status) this.scale = xscale;

        return status;
      }      
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消