Creating A Special Type of Swing List Display

H

Hal Vaughan

I want to use something like a list, but with a few changes. I'm hoping
there's an easy way to do this that I don't know about or that is so
obvious I've overlooked it. I essentially want a list with multi-line
items that can be scrolled in discrete increments. Each list item is a
name and address, like this:

John Doe
221B Baker St
New York, NY, 12345

(This has to fit in a legacy app, so I can't use a single line long enough
to fit all the info on one line.)

When scrolling, I'd like to scroll one complete address at a time, so moving
up or down won't scroll part way up to show the street or city on the top
line and part of the next item on the following line.

I know I can set the height for each item by pixels, but then I have to deal
with possible fonts and problems like that.

I've considered just using a text box and a scroll bar, getting the value of
the scroll bar and using that to figure out which item to display, and have
my code pick that item and put it in the text box. Is there an easier way
to work with discrete items that are multiple lines?

Any suggestions?

Hal
 
D

Daniel Pitts

Hal said:
I want to use something like a list, but with a few changes. I'm hoping
there's an easy way to do this that I don't know about or that is so
obvious I've overlooked it. I essentially want a list with multi-line
items that can be scrolled in discrete increments. Each list item is a
name and address, like this:

John Doe
221B Baker St
New York, NY, 12345

(This has to fit in a legacy app, so I can't use a single line long enough
to fit all the info on one line.)

When scrolling, I'd like to scroll one complete address at a time, so moving
up or down won't scroll part way up to show the street or city on the top
line and part of the next item on the following line.

I know I can set the height for each item by pixels, but then I have to deal
with possible fonts and problems like that.

I've considered just using a text box and a scroll bar, getting the value of
the scroll bar and using that to figure out which item to display, and have
my code pick that item and put it in the text box. Is there an easier way
to work with discrete items that are multiple lines?

Any suggestions?

Hal

Its generally considered a feature that you can scroll part way, its
easier for human eyes to follow. You might just want to put a better
seperator between the entries.
 
H

Hal Vaughan

Daniel said:
Its generally considered a feature that you can scroll part way, its
easier for human eyes to follow. You might just want to put a better
seperator between the entries.

Generally, yes, but in this case, due to restricted space available (I can't
do anything about that), I can fit one address in easily and I want to
avoid any confusion by making it move in discrete units.

Hal
 
D

Daniel Dyer

When scrolling, I'd like to scroll one complete address at a time, so
moving
up or down won't scroll part way up to show the street or city on the top
line and part of the next item on the following line.

You probably want to look into the javax.swing.Scrollable interface. This
is already implemented by JList so over-riding one or more of the methods
may be able to achieve your desired effect.

Dan.
 
D

Daniel Pitts

Hal said:
Generally, yes, but in this case, due to restricted space available (I can't
do anything about that), I can fit one address in easily and I want to
avoid any confusion by making it move in discrete units.

Hal
Then perhaps a list (or scrollable component of any sort) isn't the way
to go, but instead have a component that displays a single address, and
two buttons that change the address being displayed.
 
L

Lew

Hal said:
Generally, yes, but in this case, due to restricted space available (I can't
do anything about that), I can fit one address in easily and I want to
avoid any confusion by making it move in discrete units.

This isn't exactly a list idiom that you describe - more of a viewport that
shows exactly one frame of information at a time. Perhaps a next/previous
idiom is more natural for your purpose?

- Lew
 
D

Daniel Pitts

Lew said:
This isn't exactly a list idiom that you describe - more of a viewport that
shows exactly one frame of information at a time. Perhaps a next/previous
idiom is more natural for your purpose?

- Lew

You are about 8 minutes to late :)
 
L

Lew

Daniel said:
You are about 8 minutes too late :)

(eight minutes earlier:)
Events that appear time-distinct in one frame of reference may be simultaneous
in another, if the interval between the events is less than the information
latency between the frames.

In other words, I hadn't refreshed from the newsgroup yet.

I feel validated that my analysis concurred with yours. You can take home the
Golden Keyboard.

- Lew
 
H

Hal Vaughan

Daniel said:
Then perhaps a list (or scrollable component of any sort) isn't the way
to go, but instead have a component that displays a single address, and
two buttons that change the address being displayed.

Okay -- you did what I could not and basically described what I want to do.
(Sometimes a big problem to being self taught is not knowing the best ways
to express what I'm trying to do -- I can visualize it, but can't always
explain it properly.)

I can't find any components or objects that do this without putting them
together on my own. Is there a way to do that easily without having to
link either a scroll bar, a slider, or next/prev buttons with an array or
linked list and a component to display them? I can do it from scratch, but
thought it worth asking if there is something already set up to handle that
kind of setup.

Hal
 
A

Andrew Thompson

Hal said:
Daniel Pitts wrote: ....

Okay -- you did what I could not and basically described what I want to do. ....
I can't find any components or objects that do this without putting them
together on my own.

Have a look at JComboBox. With an appropriate renderer,
it might suit the requirement (as I currently understand it).

Andrew T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top