#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    410
    Rep Power
    24

    JTable Scrollbar Not Work


    I created a JTable with Vertical Scrollbar (policy: ALWAYS) by NetBean 6.5. The JTable will be inserted with data by DefaultTableModel.addRow when the user runs the program.

    However, when the data are more than that the JTable can display, and I click the scrollbar buttons, the JTable cannot be scrolled up or down. It sticks.

    Why? How can I solve it?

    Many thanks.
    ------------------------------------------
    Perl Kids Kiss Perl
    Stanley
    ------------------------------------------
  2. #2
  3. Feelin' Groovy
    Devshed Supreme Being (6500+ posts)

    Join Date
    Aug 2001
    Location
    Chicago, IL
    Posts
    10,131
    Rep Power
    5058
    Please post an SSCCE; i.e., the bare minimum amount of code that compiles, runs, and correctly demonstrates only the problem and nothing else (please read the link to make sure you understand).

    ~
    Yawmark
    class Sig{public static void main(String...args){\u0066or(int
    \u0020$:"v\"ʲ\"vΤ\"".to\u0043h\u0061rArray()
    )System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
    +(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    410
    Rep Power
    24

    Thumbs up


    Sorry that I could not do so because I used NetBean to generate a lot of codes automatically. I had no idea how to do so.

    Anyway, I finally solve the problem and would like to share the key here.

    The scrollbar is dependent to the size of its object to be contained. If the size (height for vertical, width for horizontal) of the object is smaller than the scroll pane, the bar does not show.

    Therefore, when I append the row into JTable, I have to resize the preferredheight of the JTable. Thus JTable's height is enlarged and the scrollbar shows when it exceeds the height of the scroll pane.

    Comments on this post

    • tfecw agrees : Thanks for the update!
    ------------------------------------------
    Perl Kids Kiss Perl
    Stanley
    ------------------------------------------
  6. #4
  7. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2007
    Posts
    1,939
    Rep Power
    3122
    Originally Posted by stanley1610
    Sorry that I could not do so because I used NetBean to generate a lot of codes automatically. I had no idea how to do so.
    This will continue to be a problem for you. I highly, highly recommend not using any code generation for code that you do not understand.

    Comments on this post

    • Yawmark agrees : No points, but lots of agreement.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Nov 2004
    Location
    Washington DC
    Posts
    2,755
    Rep Power
    1576
    Sorry that I could not do so because I used NetBean to generate a lot of codes automatically. I had no idea how to do so.
    I don't see how SSCCE is mutually exclusive with auto generated code. You know how to drag and drop a Jtable and set the slider policy because you've already done it once. Then all that's left to do is hardcode enough data to demonstrate that the slider sticks and your done. If Netbeans can do 90% of that for you with the drag of the mouse, great! The flip side is that your excuses for not slapping together a SSCCE become even flimsier

    Comments on this post

    • Yawmark agrees : Ditto.
    Open for extension, closed for modification

IMN logo majestic logo threadwatch logo seochat tools logo