Results 1 to 5 of 5
Thread: New here and could use some help
- 07-30-2009, 01:54 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 11
- Rep Power
- 0
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. :)
-
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.1. Am I using the right Text field to do this? (JTextPane)
If a JTextArea, there's an append(...) method that works great for this. i.e,2. How might I go about adding additional information to this window without it overwriting and/or removing the original entry?
warning: the above code has not been compiled or run yet.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"); }
- 07-30-2009, 03:51 PM #3
Member
- Join Date
- Jul 2009
- Posts
- 11
- Rep Power
- 0
I think that is exactly what I am looking for... It was the .append that I was overlooking. Thanks. :)
-
You're entirely welcome, and good luck with re-starting your Java education.
- 07-30-2009, 04:43 PM #5
Member
- Join Date
- Jul 2009
- Posts
- 11
- Rep Power
- 0


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks