Scaling editable JTextPane
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;
}
}
精彩评论