Creating A Special Type of Swing List Display

Discussion in 'Java' started by Hal Vaughan, Jan 16, 2007.

  1. Hal Vaughan

    Hal Vaughan Guest

    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
    Hal Vaughan, Jan 16, 2007
    #1
    1. Advertising

  2. Hal Vaughan

    Daniel Pitts Guest

    Hal Vaughan wrote:
    > 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.
    Daniel Pitts, Jan 16, 2007
    #2
    1. Advertising

  3. Hal Vaughan

    Hal Vaughan Guest

    Daniel Pitts wrote:

    >
    > Hal Vaughan wrote:
    >> 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.


    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
    Hal Vaughan, Jan 16, 2007
    #3
  4. Hal Vaughan

    Daniel Dyer Guest

    On Tue, 16 Jan 2007 17:16:21 -0000, Hal Vaughan <>
    wrote:

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

    --
    Daniel Dyer
    https://watchmaker.dev.java.net - Evolutionary Algorithm Framework for Java
    Daniel Dyer, Jan 16, 2007
    #4
  5. Hal Vaughan

    Daniel Pitts Guest

    Hal Vaughan wrote:
    > Daniel Pitts wrote:
    >
    > >
    > > Hal Vaughan wrote:
    > >> 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.

    >
    > 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.
    Daniel Pitts, Jan 16, 2007
    #5
  6. Hal Vaughan

    Lew Guest

    Hal Vaughan wrote:
    > 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
    Lew, Jan 16, 2007
    #6
  7. Hal Vaughan

    Daniel Pitts Guest

    Lew wrote:
    > Hal Vaughan wrote:
    > > 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


    You are about 8 minutes to late :)
    Daniel Pitts, Jan 16, 2007
    #7
  8. Hal Vaughan

    Lew Guest

    Lew wrote:
    >> Perhaps a next/previous idiom is more natural for your purpose?


    Daniel Pitts wrote:
    > You are about 8 minutes too late :)


    (eight minutes earlier:)
    >> 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.


    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
    Lew, Jan 16, 2007
    #8
  9. Hal Vaughan

    Hal Vaughan Guest

    Daniel Pitts wrote:

    >
    > Hal Vaughan wrote:
    >> Daniel Pitts wrote:
    >>
    >> >
    >> > Hal Vaughan wrote:
    >> >> 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.

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


    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
    Hal Vaughan, Jan 18, 2007
    #9
  10. Hal Vaughan wrote:
    > Daniel Pitts wrote:

    ....
    > >> ...due to restricted space available ..., I can fit one address
    > >> in easily and I want..
    > >> to avoid any confusion by making it move in discrete units.

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

    ....
    > 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.
    Andrew Thompson, Jan 18, 2007
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Big Daddy

    Java 1.2 Swing vs. Java 1.5 Swing

    Big Daddy, Apr 15, 2005, in forum: Java
    Replies:
    2
    Views:
    488
    Pete Barrett
    Apr 16, 2005
  2. mkrause
    Replies:
    0
    Views:
    661
    mkrause
    May 6, 2005
  3. lizard
    Replies:
    0
    Views:
    1,750
    lizard
    Jan 30, 2006
  4. Twisted
    Replies:
    5
    Views:
    619
    Monique Y. Mudama
    Mar 30, 2006
  5. S.T
    Replies:
    2
    Views:
    565
Loading...

Share This Page