Board index » jbuilder » Saving a reference to a JTextPane

Saving a reference to a JTextPane


2004-06-15 04:58:21 PM
jbuilder13
Hi,
I want to make several classes write messages to a JTextPane which has been created by one of them. I tried to save a reference to the pane in a class which controlls the user interface; later on I want to use this reference to write to the TextPane:
JTextPane TextPane = new JTextPane();
uic.setTextPane(TextPane);
When setting TextPane to the uic slot I get a java.lang.NullPointerException
What am I doing wrong?
Regards
Wolf
 
 

Re:Saving a reference to a JTextPane

Wolf wrote:
Quote
Hi,

I want to make several classes write messages to a JTextPane which has been created by one of them. I tried to save a reference to the pane in a class which controlls the user interface; later on I want to use this reference to write to the TextPane:

JTextPane TextPane = new JTextPane();
uic.setTextPane(TextPane);

When setting TextPane to the uic slot I get a java.lang.NullPointerException

What am I doing wrong?

Regards

Wolf
So where is the code for the setTextPane method?
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html
 

Re:Saving a reference to a JTextPane

"Lori M Olson [TeamB]" < XXXX@XXXXX.COM >wrote:
Quote
Wolf wrote:

>Hi,
>
>I want to make several classes write messages to a JTextPane which has been created by one of them. I tried to save a reference to the pane in a class which controlls the user interface; later on I want to use this reference to write to the TextPane:
>
>JTextPane TextPane = new JTextPane();
>uic.setTextPane(TextPane);
>
>When setting TextPane to the uic slot I get a java.lang.NullPointerException
>
>What am I doing wrong?
>
>Regards
>
>Wolf

So where is the code for the setTextPane method?

--

Regards,

Lori Olson [TeamB]

------------

Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.

Google Advanced Newsgroup Search
www.google.ca/advanced_group_search
Other Newsgroup Searches:
www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
www.visi.com/~gyles19/fom-serve/cache/1.html

Lori,
my idea was (and maybe I'm compleately wrong)
to store a reference to an existing TextPane
'somewhere', to make it accessable to diferent
clases. My controller has the following methods
for 'storing' and 'retrieving' the reference,
but even the 'set' produces the mentioned error.
Here follows the code for both methods.
public class UIController {
....
public void setTextPane(JTextPane pane) {
TextPane = pane;
}
public JTextPane getTextPane() {
return TextPane;
}
....
}
Similar code works for passing around references
of, for example, trees, treenodes and treemodels.
I dont understand why it does'nt work with panes.
Is it posible that the pane is not really initialized
till put into a type of container?
Regards, Wolf
 

{smallsort}

Re:Saving a reference to a JTextPane

Wolf wrote:
Quote
>Wolf wrote:
>
>
>>Hi,
>>
>>I want to make several classes write messages to a JTextPane which has been created by one of them. I tried to save a reference to the pane in a class which controlls the user interface; later on I want to use this reference to write to the TextPane:
>>
>>JTextPane TextPane = new JTextPane();
>>uic.setTextPane(TextPane);
>>
>>When setting TextPane to the uic slot I get a java.lang.NullPointerException
>>
>>What am I doing wrong?
>>
>>Regards
>>
>>Wolf
>

Lori,

my idea was (and maybe I'm compleately wrong)
to store a reference to an existing TextPane
'somewhere', to make it accessable to diferent
clases. My controller has the following methods
for 'storing' and 'retrieving' the reference,
but even the 'set' produces the mentioned error.
Here follows the code for both methods.


public class UIController {

....

public void setTextPane(JTextPane pane) {
TextPane = pane;
}

public JTextPane getTextPane() {
return TextPane;
}

....
}

Similar code works for passing around references
of, for example, trees, treenodes and treemodels.
I dont understand why it does'nt work with panes.
Is it posible that the pane is not really initialized
till put into a type of container?

Regards, Wolf

Have you compiled using debug? What line exactly is the NPE occurring
on? The only thing I can see is if your uic member is not yet
initialized, you could get an NPE.
--
Regards,
Lori Olson [TeamB]
 

Re:Saving a reference to a JTextPane

On 6/15/2004 at 4:58:21 AM, Wolf wrote:
Quote
uic.setTextPane(TextPane);

When setting TextPane to the uic slot I get a
java.lang.NullPointerException
If you are getting an NPE on this line of code, it seems likely that the
problem is that "uic" is null.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
www.JPMcGrath.net/newsgroups/e-mail.html