基本上我有一个构造函数,它依赖于另一个构造函数,而另一个构造函数又依赖于第一个构造函数。这使得编码变得非常奇怪。
这里是有问题的代码:
JTextPane textpane = new JTextPane(document);
StyledDocument document = textpane.getStyledDocument();
这将创建一个 JTextPane,它使用 StyledDocument 构造函数,然后再使用 JTextPane。
请提供任何帮助,谢谢!
最佳答案
您的代码甚至无法编译,您在声明之前就使用了 document
吗?
为什么不这样做
StyledDocument document = new DefaultStyledDocument(); // or whatever implementation you wish to use
JTextPane textPane = new JTextPane(document);
关于Java 构造函数需要一个依赖于另一个构造函数的条件,而另一个构造函数又依赖于第一个构造函数。 (蛇咬住尾部),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4779064/