简体   繁体   English

覆盖 Java DefaultStyledDocument 实现

[英]Override the Java DefaultStyledDocument implementation

I'm a student.我是学生。 When I learn the GOF, I want to create the word processor mentioned in Chapter2.当我学习 GOF 时,我想创建第 2 章中提到的文字处理器。 I choose to use Java swing, I want to extend the DefaultStyledDocument and override the insertUpdate and related methods in order to implement and manage my own Element tree, so I can practice the Composite and Flyweight Pattern.我选择使用 Java swing,我想扩展 DefaultStyledDocument 并重写 insertUpdate 和相关方法,以便实现和管理我自己的 Element 树,这样我就可以实践 Composite and Flyweight Pattern。 The problem is when I override the insertUpdate method, insert newline has no effect.问题是当我覆盖 insertUpdate 方法时,插入换行符无效。 When inserting a newline, My Element tree will create a new Paragraph(BrachElement), but the cursor don't move to the next line, Swing just don't show it and my following characters just in the same line.插入换行符时,我的元素树将创建一个新的段落(BrachElement),但 cursor 不会移动到下一行,Swing 只是不显示它,我的以下字符只是在同一行中。

Can anyone help me, thanks.谁能帮帮我,谢谢。

Try this to understand how your structure changes http://java-sl.com/JEditorPaneStructureTool.html试试这个来了解你的结构是如何变化的

And this http://java-sl.com/JEditorPaneTables.html to see how to change the structures还有这个http://java-sl.com/JEditorPaneTables.html看看如何改变结构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM