Results 1 to 11 of 11
  1. #1
    glhansen is offline Member
    Join Date
    Mar 2009
    Posts
    20
    Rep Power
    0

    Default Scrolling and Headers in a scroll pane

    I'm sort of new to Java, but it was suggested on the New To Java forum that this is a better place for these sorts of questions.

    The thing that's puzzling me right now is a lack of a horizontal scrollbar. I've set a preferred size to my scroll pane, set the horizontal and vertical scrollbar policies to always, created a JList, added it to the scroll pane with

    scroller.setViewportView(patronList);

    and the list runs right off the edge without a horizontal scrollbar. The vertical scroll bar is there.

    My other question is how do I make a list with fixed-width fields? I've seen enough in Sun's documentation to think there must be away, but I can't decipher it.

    Thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Can you post a small compilable program that demonstrates your problem?

  3. #3
    glhansen is offline Member
    Join Date
    Mar 2009
    Posts
    20
    Rep Power
    0

    Default

    That's the only way, really, but it can be hard to rip it out of its context since it's getting lists and using windows and suchlike from elsewhere.

    But I've solved my scrollbar problem in the process, when I got a little tiny test window and resized it. I discovered that my horizontal scroll bar was there, but the scrolling area was bigger than the pane it was set in, so the scroll bar was hidden. And since the scroller wasn't in a scroller, I couldn't just scroll down to find it. I changed the preferred size, and it looks the way I had hoped it would.

    Thanks for the advice.

    My project is a simple library database, and in this particular window I'm matching an entered string against patron names, allowing matches on fragments of names, and posting a list for the user to browse, and he can select one to get the detailed screen.

    So I have a list of ID number, last name, first name, phone number, and address. And they all run together. I would like to allocate so much width for each piece of data, and simply cut it off if an address or something runs on longer than the field. And I can count characters and concatenate strings, but with a proportional font it would still only be approximate.

    Can I make a list with rows that have fixed-width fields?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I would suggest that you consider using a JTable and placing each field in its proper column. Otherwise you could create your own renderer for the JList and make it a JPanel with fixed width JLabels.

  5. #5
    glhansen is offline Member
    Join Date
    Mar 2009
    Posts
    20
    Rep Power
    0

    Default

    That looks suspiciously close to what I had in mind.

    I'm still relying on my Java tutorial which, fat as it is, seems to cover only a small fraction of what is available. I might have to go shopping for a Swing manual or something.

    Thanks again.

  6. #6
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    JTable has method setAutoResizeMode
    default value is JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS, no horizontal scroll
    if you change to JTable.AUTO_RESIZE_OFF, horizontal scroll would appear

    if JTable.AUTO_RESIZE_OFF, you need to take care your column width of table
    you may check your totalColumnWidth of by getColumnModel().getTotalColumnWidth, and decide weather to use AUTO_RESIZE_OFF or other AutoResizeMode of JTable

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default

    Before you go shopping, you might like to take a look at
    Trail: Creating a GUI with JFC/Swing (The Java™ Tutorials)

    db

  8. #8
    glhansen is offline Member
    Join Date
    Mar 2009
    Posts
    20
    Rep Power
    0

    Default

    I've figured out how to do a lot of things with Java and Swing, but I always wonder if I have a kludged-together mess that everyone else does differently. I think Swing must be great for the OOP geek, but it's not exactly designed with the beginner in mind.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I'll agree with you there, but once you delve into it, it's a let-down going back to Microsoft's Visual Studio and pointing and clicking to create GUIs (at least for me).

  10. #10
    glhansen is offline Member
    Join Date
    Mar 2009
    Posts
    20
    Rep Power
    0

    Default

    I haven't used Microsoft's Visual Studio, but I can imagine it being a let-down. I wouldn't want to simplify or stupidify Swing. But I think it would be nice to have a tutorial showing "best practices" uses of it. And I can look up the APIs on Sun's web site, so save pages on comprehensiveness and discuss use.

    Do you have a favorite manual of that type?

    Darryl suggested Sun's tutorials. I haven't had the time to look at much of them yet, but I suspect they would be kind of short compared with what I'd be looking for.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    They're a great place to start. This is where Darryl and I learned our Swing coding (and he really knows his stuff).

Similar Threads

  1. MouseMotionListener 'scrolling'
    By Thez in forum Java 2D
    Replies: 3
    Last Post: 03-12-2009, 11:48 AM
  2. Scroll message
    By getkiran in forum Java Applets
    Replies: 1
    Last Post: 03-05-2009, 04:29 AM
  3. tooltips for JTable column headers
    By fossildoc in forum AWT / Swing
    Replies: 2
    Last Post: 12-18-2008, 11:42 AM
  4. AWT Table Scrolling
    By albert_kam in forum AWT / Swing
    Replies: 0
    Last Post: 01-03-2008, 11:37 AM
  5. Jtextarea and scroll
    By ziniestro in forum AWT / Swing
    Replies: 2
    Last Post: 06-01-2007, 03:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •