Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE while giving new content to a JEditorPane #47

Closed
GoogleCodeExporter opened this issue Oct 25, 2015 · 10 comments
Closed

NPE while giving new content to a JEditorPane #47

GoogleCodeExporter opened this issue Oct 25, 2015 · 10 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. instanciate a new JEditorPane
2. perform a setText on it with some content
3. call setContentType("text/java") on this JEditorPane

What is the expected output? What do you see instead?
It should work fine since the component is not visible yet.
Unfortunately, a NPE is thrown.

What version of the product are you using? On what operating system?
0.9.4a on OSX 10.6


Please provide any additional information below.

A NPE is thrown in the getLineNumber() method of ActionUtils class because
the JEditorComponent has not been sized yet. Therefore, the call
editor.modelToView(pos) will return a null reference, and the next
instruction r.y will throw a NPE.


Original issue reported on code.google.com by oste...@gmail.com on 24 Dec 2008 at 10:53

@GoogleCodeExporter
Copy link
Author

This is strange.  The component should have its size already, unless there is
something wrong.
Can you send/paste me the whole code, instead of just the steps above?

Original comment by ayman.al...@gmail.com on 30 Dec 2008 at 10:57

@GoogleCodeExporter
Copy link
Author

Original comment by ayman.al...@gmail.com on 30 Dec 2008 at 10:57

@GoogleCodeExporter
Copy link
Author

In my project, I encountered the problem when dynamically adding or removing
JEditorPane in tabs of a JTabbedPane.

Please find attach the smallest piece of code that I was able to write in order 
to
reproduce the NullPointerException. You have to click on the JButton in order to
generate the NPE.

P.S: thanks a lot for your wonderful piece of code!

Original comment by oste...@gmail.com on 30 Dec 2008 at 1:06

Attachments:

@GoogleCodeExporter
Copy link
Author

I just fixed it in the latest release (r64).  It missed the binary release by 
just a
few minutes.
You also need to call the doLayout method on the container just after the add is
called.  Otherwise it wont display immediately.
        c.add(scrPane, BorderLayout.CENTER);
                c.doLayout();

Original comment by ayman.al...@gmail.com on 30 Dec 2008 at 1:39

  • Changed state: Fixed
  • Added labels: Type-Defect

@GoogleCodeExporter
Copy link
Author

I tried the latest release (r64). There is no more NPE. Unfortunately, there is 
still
a problem, the lines are not correctly numbered. For instance, if you try to 
execute
my previous TestIssue47 class while providing a multi-line content as parameter 
of
the setText method (setText("xxx\nxxx\nxxx");), only the first line is numbered 
;(. 

Original comment by oste...@gmail.com on 30 Dec 2008 at 3:21

@GoogleCodeExporter
Copy link
Author

In that case, maybe other things could fail.  You should call the setContentType
after calling doLayout on the component.  Let me know if that does not work.

Original comment by ayman.al...@gmail.com on 30 Dec 2008 at 4:16

@GoogleCodeExporter
Copy link
Author

Unfortunately, it seems the problem is not related to the doLayout() as 
illustrated
in the code attached to this comment. In this example, doLayout() is called 
before
the setContentType(), and latter the setText() is called. 

Original comment by oste...@gmail.com on 30 Dec 2008 at 6:07

Attachments:

@GoogleCodeExporter
Copy link
Author

The problem is that the LineNumbersRuler component is a CaretListener, but the 
Caret
is not moved by the initial setText.  I implemented a CaretListener because at 
time
of registering the LineNumbersRuler to the component, the Editor's 
SyntaxDocument is
yet available.  
I'll look at a better solution.  Seems like listening for the components
propertyChange and implementing a DocumentListener will be needed.

Original comment by ayman.al...@gmail.com on 31 Dec 2008 at 5:14

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Fixed in r65.  I did the above, and also don't call the modelToView, relying on 
the
Document Elements now.
Many thanks for keeping me honest :-)

Original comment by ayman.al...@gmail.com on 31 Dec 2008 at 8:12

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

It works like a charm ! 
Thank you very much for your effort and one more time thank you for providing 
us such
a useful component.

Original comment by oste...@gmail.com on 31 Dec 2008 at 9:12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant