Link to home
Start Free TrialLog in
Avatar of b612_forever
b612_forever

asked on

Question Regarding JList and JScrollPane

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.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of b612_forever
b612_forever

ASKER

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.
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.
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.
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
8-)