Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JTextArea with JScrollPane

Posted on 2004-08-30
9
Medium Priority
?
634 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 11931208
>> 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
ID: 11931236
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
ID: 11935901
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 11937313
inside your loop, add the text using:

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

Expert Comment

by:expertmb
ID: 11938509
>> 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
ID: 11938529
>>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
ID: 11938532
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

604 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