Results 1 to 6 of 6

Thread: JTextPane array

  1. #1
    SankaR7 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Lightbulb JTextPane array

    I am trying to create an array of JTextPane and the add different icons to the elements.

    So i created the array by doing this:
    JTextPane[] normPane = new JTextPane[4];

    But now when i try to insert and icon into say for example normPane[0] like this:
    normPane[0].insertIcon(icon);


    which is how i would insert an icon to a regular JTextPane, i get run time errors

    Am I not accessing the arrays in the right manner?
    Not quite sure how to fix this.
    Would appreciate any help!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: JTextPane array

    You allocated space for the array to hold 4 text panes, but the array is empty. You need to add text panes to the array:
    Java Code:
    normPane[0] = new JTextPane();
    normPane[0].insertIcon(icon);

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: JTextPane array

    Quote Originally Posted by camickr View Post
    You allocated space for the array to hold 4 text panes, but the array is empty. You need to add text panes to the array:
    Java Code:
    normPane[0] = new JTextPane();
    normPane[0].insertIcon(icon);
    I assumed this too, but I wanted to get the original poster to post his error messages so he could see for himself that he had a NullPointerException and what that meant, and so he would get in the habit of posting all the pertinent information when asking a question here.

  5. #5
    SankaR7 is offline Member
    Join Date
    Nov 2011
    Posts
    7
    Rep Power
    0

    Default Re: JTextPane array

    Quote Originally Posted by Fubarable View Post
    I assumed this too, but I wanted to get the original poster to post his error messages so he could see for himself that he had a NullPointerException and what that meant, and so he would get in the habit of posting all the pertinent information when asking a question here.
    Thanks guys for the help i get it now.

    And sorry for not posting all the pertinent information like i should have. Will be sure to make note of that and do it next time.

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default Re: JTextPane array

    Quote Originally Posted by Fubarable View Post
    I assumed this too, but I wanted to get the original poster to post his error messages so he could see for himself that he had a NullPointerException and what that meant, and so he would get in the habit of posting all the pertinent information when asking a question here.
    Sorry about that Pete, I didn't mean for the poster ignore your answer. I often answer questions with advice like that and get annoyed when someone spoonfeeds the answer.

    I have a bad habbit of opening multiple windows with the questions I intend to answer. Sometimes, by the time I get around to answer the question other suggestions have already been made :)

Similar Threads

  1. JTextPane problem
    By mitra in forum AWT / Swing
    Replies: 2
    Last Post: 08-04-2011, 08:25 AM
  2. XML + XSL in JTextpane
    By Stijn_vdd in forum AWT / Swing
    Replies: 0
    Last Post: 03-10-2011, 03:51 PM
  3. JTextPane
    By xXx BlitzK xXx in forum AWT / Swing
    Replies: 1
    Last Post: 12-16-2010, 08:08 AM
  4. problem in JTextPane
    By jperson in forum New To Java
    Replies: 4
    Last Post: 07-07-2010, 05:57 PM
  5. JTextpane
    By Mash in forum AWT / Swing
    Replies: 1
    Last Post: 04-15-2010, 07:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •