Solved

Question Regarding JList and JScrollPane

Posted on 2004-03-22
6
471 Views
Last Modified: 2012-05-04
Problem 1:
I am now using a JList with default selection mode MULTIPLE_SELECTION. This allow user to make multiple selection by holding the Ctrl key and clicking on the left mouse button. And it work fine.

My first Question is:
if I would like to let user to make multiple selection WITHOUT holding on Ctrl key, how should I code?

Problem 2
I am using a loop to append text into a JTexArea which is contain in a JScrollPane. I use the JTextArea.append(String str) to append the string. It also work fine but the user will only see the top portion of the JTextArea if they do not scroll it manually to the bottom.

My second question is:
How to scroll the JScrollPane automatically to the bottom of the JTextArea after each time append text to it?

Thank You.
0
Comment
Question by:b612_forever
[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
  • 3
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 150 total points
ID: 10654421
1. Don't. This is how that particular control should work and guis should behave in a predictable way
2. textArea.setCaretPosition(textArea.getDocument().getLength());
0
 
LVL 1

Author Comment

by:b612_forever
ID: 10654550
Thanks to CEHJ for answering, the code in the answer for question 2 is work. So the question 2 is closed.

For question 1, my scenario is a bit different, most of my option in the JList is by default selected and user are expected to deselected some of them.

So if the user do not hold on Ctrl key while deselected on one of the option, the result will be that the user will deselect all options previously selected and the option that they would like to deselect will become the only option selected.

To prevent this, I need to let user selected and deselect in both WITH and WITHOUT holding on Ctrl key. (This is correction to my question where I only mentioned 'WITHOUT').

Thank You.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10654590
The short answer is i don't know, but i still don't think you ought to do it even if you can. This is a slightly 'power user' feature of list boxes and is perfectly normal. A better thing to do would be to ensure that users know how to use these controls. Training them in the 'wrong way' is only going to confuse them more in the end.
0
Industry Leaders: 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 1

Author Comment

by:b612_forever
ID: 10762427
This question is open for too long and i think it is time to close it. However, before I close it, I have another question similar to the question 2 I asked previously:

>> Instead of JtextArea, I put a JTable into a JScrollPane and would like to ensure the JTable always scrolled to the bottom automatically?

Since this question is not in the original questioned asked, I increased the point for this question for 50.
0
 
LVL 20

Expert Comment

by:Venabili
ID: 10858343
b612_forever,

You cannot ask additional questions in the same thread, even if you increase the points. Please award here the experts that had helped you and ask your new questions separately. Thanks

Venabili
EE Page Editor for Java
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10866795
8-)
0

Featured Post

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!

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
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 covers a step-by-step guide to install VisualVM launcher in eclipse.

740 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