Solved

Question Regarding JList and JScrollPane

Posted on 2004-03-22
6
470 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 62
eclipse console opening separately 2 29
Chrome and Firefox Java 5 50
Notify sent to other threads in Java 9 33
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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:

840 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