Results 1 to 10 of 10
Thread: Cant refresh JFrame, jTextArea1
- 01-25-2011, 02:48 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 28
- Rep Power
- 0
Cant refresh JFrame, jTextArea1
Hello experts
I created a java program using netbeans (palette), the output is displayed in JTextArea,
Part of the code
The output in jTextArea1 is displayed after the code is excuted and not as per the code in which it appends the data at each line of the for loopJava Code:for ( i = 0; i < cArray.length; i++) { if (cArray[i].contains("96279")) { Command = CommandPart1 + cArray[i] + CommandPart2; String run = thr.run(Command); System.out.println(cArray[i] + ": " + run); jTextArea1.append(cArray[i] +": "+ run + "\n"); jTextArea1.revalidate(); this.repaint() ; } }
, in the System.out, it's displayed line by line with no problem ?
I tried to use repaint, validate, revalidate
Can any body help
- 01-25-2011, 04:43 PM #2
Member
- Join Date
- Jan 2011
- Posts
- 27
- Rep Power
- 0
after looking around i found this line of code
jTextArea.update(jTextArea.getGraphics());
that seemed to fix similar problems for some. If that doesn't work i read that multi-threading may be needed. Do a search fro refresh jtextarea. Hope this helps
- 01-25-2011, 05:11 PM #3
If you want help, you'll have to provide an SSCCE that demonstrates what you're actually doing. For example, is this code running on the EDT? In another Thread?
I would bet you're doing this on the EDT, which is causing all of the repaint() calls to be pushed to the end. You might want to look at the paintImmediately() method, or you might want to move logic that takes a long time off of the EDT.
Edit- And no, using the update method is probably not the way to go. If you're calling the getGraphics() method of a Component, you're doing something very wrong.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
-
I have a suspicion that this is a Swing threading issue, and that you have a Thread.sleep or while (true) lurking in code not shown us. If so, use a Swing Timer instead. If not, then as Kevin wisely suggests, create and show us an SSCCE. I also agree that you should ignore Debugger's advice. While he means well, it's off the mark.
- 01-26-2011, 07:42 AM #5
Member
- Join Date
- Sep 2008
- Posts
- 28
- Rep Power
- 0
Thanks a lot debugger and all..
it's working fine now.. I just added jTextArea.update(jTextArea.getGraphics());
-
- 01-26-2011, 12:19 PM #7
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-27-2011, 01:45 PM #8
Member
- Join Date
- Jan 2011
- Posts
- 27
- Rep Power
- 0
Was not meant to confuse him, just a though of what may fix it, if he/she chooses to look into it more is up to them, which is why i also mentioned the threading issue, which has been the case for me before.
As i said before simply trying to help, but i'm obviously not as advanced as some so i would look into what they are saying,
- 01-27-2011, 01:57 PM #9
We (I) don't mind less experienced users trying to help - heck, I don't really consider myself as "advanced" as most of the veterans here either. But coding Swing correctly takes practice, and it takes time to understand some of the more common problems- two of which you had in your reply.
Using getGraphics() on a Component is almost never ever a good idea. It might seem to fix one problem, but I guarantee it's going to cause other, less fixable problems down the road.
And telling the OP to use multi-threading is opening up a dangerous can of worms and is probably more misleading than it is informative. Sure, I can see one way of using it to fix this particular problem, especially because the append method is one of the few cases of a thread-safe method in Swing, but that doesn't mean that it's the best way to go. I'd say using a Swing Timer is probably more what the OP is looking for. Until you understand the EDT and all of its magic, you almost definitely should not be mixing threading and Swing.
I'm not trying to be mean or discourage you from helping, but this is a good example of when the first thing to pop into your head isn't actually the correct way to go. But the OP will probably continue to follow your advice, and it will eventually give him bigger problems.How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 01-27-2011, 02:05 PM #10
Member
- Join Date
- Jan 2011
- Posts
- 27
- Rep Power
- 0
well then i guess he will learn his lesson and not listen to me =p i understand what your saying though which is why im open to criticism. I knew what i meant in my head, but did not portray it correctly to them, should have been more specific.
If they were a good programmer, they would read more into than just my post, and wish to understand WHY that fixes it, and would like i now do realize that it fixes that issue but will result in more.
Similar Threads
-
to pass a parameter from a jframe children to its jframe mother
By anix in forum NetBeansReplies: 5Last Post: 06-14-2010, 06:10 PM -
Passing data from one JFrame to another JFrame. - need help.
By Unsub in forum New To JavaReplies: 6Last Post: 04-12-2010, 11:33 AM -
JFrame refresh problem
By elliot in forum AWT / SwingReplies: 5Last Post: 02-03-2010, 11:18 PM -
Passing data from one JFrame to another JFrame
By tarami in forum New To JavaReplies: 3Last Post: 08-06-2009, 05:44 PM -
How to make a Jframe un-focusable when another Jframe is active?
By Robert_85 in forum Advanced JavaReplies: 4Last Post: 04-22-2009, 11:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks