Jscrollpane and jtable

Discussion in 'Java' started by yashiro, May 17, 2008.

  1. yashiro

    yashiro Guest

    Hello every body.
    I have a jtable in a jscrollpane.
    How to adjust the size of the scrollpane (height) to be the same of
    the jtable, so that there is no vertical scroll ? because when i fixe
    a size for the jcrollpane, i got a few row in my jtable, i got a big
    empty space.

    thank you for you help
    yashiro, May 17, 2008
    #1
    1. Advertising

  2. yashiro wrote:
    > Hello every body.
    > I have a jtable in a jscrollpane.
    > How to adjust the size of the scrollpane (height) to be the same of
    > the jtable, so that there is no vertical scroll ? because when i fixe
    > a size for the jcrollpane, i got a few row in my jtable, i got a big
    > empty space.
    >
    > thank you for you help

    I'm not sure to understood you problem.
    If you want to remove the vertical scrool bar use this:

    jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

    --
    Andrea Francia
    http://code.google.com/p/remoted-list/ - Lazy loading lists through RMI.
    Andrea Francia, May 17, 2008
    #2
    1. Advertising

  3. yashiro

    Jeff Higgins Guest

    yashiro wrote:
    > Hello every body.
    > I have a jtable in a jscrollpane.
    > How to adjust the size of the scrollpane (height) to be the same of
    > the jtable, so that there is no vertical scroll ? because when i fixe
    > a size for the jcrollpane, i got a few row in my jtable, i got a big
    > empty space.
    >
    > thank you for you help


    Using SimpleTableDemo.java as an example.
    SimpleTableDemo is discussed here:
    <http://java.sun.com/docs/books/tutorial/uiswing/components/table.html>

    changing lines 73 - 74

    from:
    table.setPreferredScrollableViewportSize(new Dimension(500,70));
    table.setFillsViewportHeight(true);

    to:
    table.setPreferredScrollableViewportSize
    (new Dimension(500, table.getRowCount() * table.getRowHeight()));
    table.setFillsViewportHeight(false);

    seems to accomplish what (it seems to me) you are asking for.
    Jeff Higgins, May 17, 2008
    #3
    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. Happy Day
    Replies:
    5
    Views:
    8,176
    Rogan Dawes
    Aug 17, 2005
  2. Tintin92
    Replies:
    1
    Views:
    1,672
    Andrew Thompson
    Feb 14, 2007
  3. Allan Valeriano

    Set size of JTable inside a JScrollPane

    Allan Valeriano, Jun 15, 2007, in forum: Java
    Replies:
    1
    Views:
    13,158
    Andrew Thompson
    Jun 16, 2007
  4. Replies:
    3
    Views:
    1,559
    timjowers
    Jul 19, 2007
  5. Haircuts Are Important
    Replies:
    3
    Views:
    296
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page