缩放可编辑 JTextPane
我想缩放 JTextPane 以进行内联文本编辑。用户可以缩放/平移文本并双击 JLabel 进行编辑。编辑器应该缩放到当前的缩放级别。
我扩展了 JTextPane 并通过缩放组件图形进行绘制。但是,编辑不能以不同于 1 的比例进行。
如何缩放可编辑的 JTextPane?
任何解决方案/指针都会有帮助。提前致谢。
我没有找到相关的问题< /a> 有用。
以下仅缩放组件并以不同比例绘制。然而编辑并没有缩放。
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;
}
}
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论