Solved

Question Regarding JList and JScrollPane

Posted on 2004-03-22
6
465 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Author Comment

by:b612_forever
Comment Utility
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
Comment Utility
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
Comment Utility
8-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Basics of Drool Rule Engine with few samples 2 39
countPairs challenge 7 57
countHi2 challenge 7 43
for i loop in grovy 1 32
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now