Solved

Question Regarding JList and JScrollPane

Posted on 2004-03-22
6
468 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JList custom Cell Renderer refresh 15 57
servlet doXXX methods 3 51
expectj telnet failing 5 37
Java: The Public Class Main 4 17
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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:

831 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