Results 1 to 4 of 4
  1. #1
    Martino is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default How to update the scrollbar?

    Hi,

    I have a little problem with programming a vertical scroll bar for scrolling a Graphics panel.

    At specific moments, the vertical scroll bar is being updated. This is, because a new item is drawn to the panel or an item is removed. As a consequence the height of the panel changes, and so, the vertical scroll bar has to be changed too.

    But now I have the following problem. When you, for example, make the frame bigger, the scroll bar should update, but it did not succeed.

    How can I update the scroll bar, when the size of the window/panel changes? It is an event. But, what event is that? Is that an event of WindowListener or WindowStateListener? Please help! Thank you in advance!

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

    Default

    Neither. ComponentListener.

    But why are you reinventing JScrollPane?

    db

  3. #3
    Martino is offline Member
    Join Date
    Apr 2011
    Posts
    12
    Rep Power
    0

    Default

    Hi,

    Thanks for the answer.

    What do you mean with 'reinventing the wheel'? Is there an easier to build to scroll bar for scrolling graphics?

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,227
    Rep Power
    6

    Default

    Is there an easier to build to scroll bar for scrolling graphics?
    All you need to manage is the "preferred size" of you panel. Override the getPreferredSize() method to return the proper based based on the items your draw. Whenever you add/remove an item you invoke;

    Java Code:
    revalidate();
    repaint();
    on the panel and the layout manager code will look after the scrollbars of the scrollpane. Resizing of the frame will also be handled automatically as well.

Similar Threads

  1. Custom scrollbar possible?
    By FatWhale in forum AWT / Swing
    Replies: 2
    Last Post: 03-19-2011, 02:37 PM
  2. ScrollBar in a JList
    By lupo in forum AWT / Swing
    Replies: 2
    Last Post: 05-20-2010, 10:42 PM
  3. scrollbar issue
    By kumar_gemi in forum New To Java
    Replies: 9
    Last Post: 05-06-2009, 06:57 AM
  4. scrollbar issue
    By kumar_gemi in forum NetBeans
    Replies: 1
    Last Post: 05-03-2009, 10:23 PM
  5. Using java.awt.Scrollbar
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-03-2008, 09:19 AM

Posting Permissions

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