【发布时间】:2015-10-11 02:41:18
【问题描述】:
我可能以错误的方式处理这件事。请赐教。提前谢谢!!!
void initialize() {
more code...
JEditorPane textPane = new JEditorPane();
textPane.setEditable(false);
textPane.setBackground(Color.LIGHT_GRAY);
textPane.setText(" THE MESSAGE I WANT TO CHANGE FROM OUTSIDE initialize()");
more code....
public static void SomePrintClass(){
JEditorPane textPane = new JEditorPane();
textPane.setText("SOME NEW TEXT ); // I am aware this doesn't work
//but is there a way it can be made to work???
more code.....
【问题讨论】:
-
如果没有更多代码,可能很难指导您,但是您能否不将 textPane 的实例传递给 SomePrintClass 的构造函数,以便它持有所需的引用?
-
@Michael 这听起来很明智,你能给我举个例子说明你会怎么做吗?
-
您想从任何其他类更改 JEditorPane 吗?
-
@CodeRunner 这可能会让我的生活更轻松。我正在尽一切可能找到最适合我正在构建的程序的方法。
-
您可以通过我的示例对 JEditoPane 执行所有操作。我编辑了答案。更改了 JEditorPane 的字体颜色。