?
Solved

JTextArea with JScrollPane

Posted on 2004-08-30
9
Medium Priority
?
628 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

752 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