Results 1 to 5 of 5
  1. #1
    DaFlake is offline Member
    Join Date
    Jul 2009
    Posts
    11
    Rep Power
    0

    Default New here and could use some help

    Hey all!

    I am new here (love the forum) and I am trying to get back into JAVA. I have a class that will be starting in the Fall, and since it has been two years I thought I would ramp myself back up. Now, I can use a little help...

    I have taken course work from a school and I am making a GUI using netbeans. (I don't want to post code as it is still used by several schools)

    What I am trying to do is this... I have my JFrame that has my buttons and outputs my result (singular) to a JTextPane (works fine). However, what I now want to do is have multiple results scroll down this pane rather than just a single result. I have a line that uses setText to output to that field. I have searched but I can't seem to find a way to add to that field without it deleting the previous entry.

    1. Am I using the right Text field to do this? (JTextPane)

    2. How might I go about adding additional information to this window without it overwriting and/or removing the original entry?

    For instance, if my program where to output a count (1 - 10), I would want to see...

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    in the window.

    Thanks in advance for your help... Also, I am not looking for total handouts here, I just want to be pointed in the right direction so that I can ramp up my skills again. :)

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

    Default

    1. Am I using the right Text field to do this? (JTextPane)
    If you want a simple text component to display multiple lines of text, I'd suggest using a JTextArea, perhaps placed in a JScrollPane. JTextPane is for displaying complex formatted text.

    2. How might I go about adding additional information to this window without it overwriting and/or removing the original entry?
    If a JTextArea, there's an append(...) method that works great for this. i.e,

    Java Code:
    JTextArea myTextArea = new JTextArea(20, 40); // 20 rows, 40 columns
    JScrollPane scrollPane = new JScrollPane(myTextArea);
    
    // then add the scrollpane to the GUI
    
    for (int i = 0; i < 10; i++) {
      myTextArea.append(String.valueOf(i) + "\n");
    }
    warning: the above code has not been compiled or run yet.

  3. #3
    DaFlake is offline Member
    Join Date
    Jul 2009
    Posts
    11
    Rep Power
    0

    Default

    I think that is exactly what I am looking for... It was the .append that I was overlooking. Thanks. :)

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

    Default

    You're entirely welcome, and good luck with re-starting your Java education.

  5. #5
    DaFlake is offline Member
    Join Date
    Jul 2009
    Posts
    11
    Rep Power
    0

    Default

    Thanks... It has been interesting to see how much I have forgotten in two plus years. However, the more that work with it the more that comes back to me. Just to let you know, the tip above worked perfectly and the program now does what I wanted it to do. I'm glad that I found this site.

Posting Permissions

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