Article View: borland.public.jbuilder.java.swing
Article #776Re: making sense of runtime error
From: Paul Furbacher [TeamB]
Date: Thu, 23 Dec 2004 04:38
Date: Thu, 23 Dec 2004 04:38
78 lines
3422 bytes
3422 bytes
Alan Shiers wrote:
> The JScrollPane is definitely trying to repaint itself, but failing for some
> reason.
> Just for your further information...my project is not that complicated.
In some sense, it seems to me that you may have made
it needlessly complicated by introducing the threading.
Somehow, you are probably mangling the UI thread, or
something like that with the code shown below. (I'm
just taking a wild guess because I cannot really make
sense of what you are trying to do, not at least from
my house [a carpenter's saying for "from this great
distance"].)
Maybe you want to do an SwingUtilities.invokeLater
bit of magic here, instead of starting the thread
as you do. Why is it necessary to introduce
this special threading?
> My
> main class that extends JFrame declares an instance of JScrollPane at the
> top, then loads the JScrollPane in an actionPerformed method like so:
>
> public class test extends JFrame implements ActionListener
> {
> JScrollPane sp2 = new JScrollPane();
> DocumentPanel docPanel = null;
> JMenuItem New = new JMenuItem("New");
> ...
>
> public void actionPerformed(ActionEvent e)
> {
> if(e.getSource() == New)
> {
> Thread newThread = new Thread()
> {
> public void run()
> {
> //Display a new DocumentPanel
> docPanel = new DocumentPanel();
> sp2.getViewport().add(docPanel);
> container.add(sp2,BorderLayout.CENTER);
> container.validate();
> }
> };
> newThread.start();
> }
> }
> }
> [/code]
>
> docPanel is an object I created that extends JPanel and contains many other
> objects.
>
> In the same actionPerformed() method is the code for saving the docPanel
> seen in the earlier post. So, any further ideas as to how to prevent the
> NullPointerException I've been getting with the JScrollPane?
>
> Alan
>
>
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Technical Details
Message-ID:
<41ca4bc5@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41c887e9$1@newsgroups.borland.com> <41c98187$1@newsgroups.borland.com> <41c9a796$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,a48625165a64e13d X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 22 Dec 2004 23:38:32 -0500 From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com> Organization: Reverse Alchemy, Inc. User-Agent: Mozilla Thunderbird 0.8 (Macintosh/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing Subject: Re: making sense of runtime error References: <41c887e9$1@newsgroups.borland.com> <41c98187$1@newsgroups.borland.com> <41c9a796$1@newsgroups.borland.com> In-Reply-To: <41c9a796$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.142.222.65 Message-ID: <41ca4bc5@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1103776709 69.142.222.65 (22 Dec 2004 20:38:29 -0800) Lines: 78 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail