Solved

JTextArea with JScrollPane

Posted on 2004-08-30
9
619 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 92

Accepted Solution

by:
objects earned 125 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This video teaches viewers about errors in exception handling.

726 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