Solved

JTextArea with JScrollPane

Posted on 2004-08-30
9
600 Views
Last Modified: 2008-02-26
Problem:
In a Java Swing Application (JFrame), I added JScrollPane and JButton. Inside JScrollPane,  a JTextArea is added. The problem is, when i press the button, it is dynamically adding some text to JTextArea continuously. During the time, the scrollbar is not coming in JScrollPane. But, at the end it is coming. I want the scrollbar has to come during run-time(in loop execution).

Before post this question, i searched in some of the discussion forums. but i cannot find the answe for the above problemr. If it is not possible, I want the solution for that situation in any other way. Please write the code also.

Thanks a lot.

-R.Ramaraj
0
Comment
Question by:itramaraj
9 Comments
 
LVL 37

Expert Comment

by:zzynx
Comment Utility
>> it is dynamically adding some text to JTextArea continuously.
Don't get that one.

>> But, at the end it is coming.
At the end of what?
0
 
LVL 18

Expert Comment

by:armoghan
Comment Utility
One way that might work is to refresh/repaint the JScrollPane. That may not be a very good way but will work.

0
 
LVL 3

Expert Comment

by:CI-Ia0s
Comment Utility
Perhaps add the scrollbar at the beginning. After creating the JScrollPane put these in (if you need a horizontal scrollbar change "never" to "always"):
scrollPaneObject.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPaneObject.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 92

Accepted Solution

by:
objects earned 125 total points
Comment Utility
inside your loop, add the text using:

EventQueue.invokeLater(new Runnable()
{
   public void run()
   {
      // append text here
   }
});
0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
>> During the time, the scrollbar is not coming in JScrollPane. But, at the end it is coming. I want the scrollbar has to come during run-time(in loop execution).

if you dont set any scrollbar policy, default scrollbar policy is applied.
VERTICAL_SCROLLBAR_AS_NEEDED
HORIZONTAL_SCROLLBAR_AS_NEEDED

thts why scrollbar is appearing at the end.




0
 
LVL 6

Expert Comment

by:expertmb
Comment Utility
>>I want the scrollbar has to come during run-time(in loop execution).  
before entering into the loop set the scrollbar policy.
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
0
 
LVL 3

Expert Comment

by:CI-Ia0s
Comment Utility
Aye. To go a bit further on what expertmb said: The scrollbar is needed partway through the thread in which the text is being added. However, the "GUI" thread is yielding to the "processing" thread, and until the "processing" thread pauses, the "GUI" thread will not update (even with a validate/repaint). The simple solution is as I suggested above, add the scrollbars at the beginning. :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
array6 challenfge 6 62
allStar challenge 1 40
nestparen challenge 4 55
advertisement module in core php 4 79
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now