Set size of JTable inside a JScrollPane

Discussion in 'Java' started by Allan Valeriano, Jun 15, 2007.

  1. Hi,

    I'm inserting a JTable into a JScrollPane which is inserted inside a
    JPanel. I'd like to set the size of this JScrollPane to be the same as
    the JPanel, so it will show a blank space between the end of my JTable
    and the end of my JScrollPane.
    I've tryed something like:

    table.setPreferredScrollableViewportSize(panel.getSize());

    but is not working as I wanted. On this picture, there is a grey space
    between the end of the table and the end of the window:
    http://java.sun.com/docs/books/tutorial/figures/uiswing/components/TableRenderDemo.png

    This is because the JScrollPane resizes itself, to fit the size of the
    table, but I want it not to resize like that if the table is smaller
    then the Panel, so there will be a blank space between the last table
    row and the end of the JScrollPane and not between the end of the
    JScrollPane and the end of the window.

    Does anybody knows how can I do that?
     
    Allan Valeriano, Jun 15, 2007
    #1
    1. Advertising

  2. Allan Valeriano wrote:
    ...
    >...show a blank space between the end of my JTable
    >and the end of my JScrollPane.
    >I've tryed something like:


    Please do not wast your time, and our bandwidth,
    describing 'something like' the code, input or output.
    SSCCE's* and copy/pasted input and output are 1000%
    more useful.

    * <http://www.physci.org/codes/sscce.html>

    >table.setPreferredScrollableViewportSize(panel.getSize());
    >
    >but is not working as I wanted.


    What layouts are you using? (considers) No, answer
    that in your SSCCE.

    >..On this picture, there is a grey space
    >between the end of the table and the end of the window:
    >http://java.sun.com/docs/books/tutorial/figures/uiswing/components/TableRenderDemo.png


    I see a white space when I run the code in Java 6..
    <http://java.sun.com/docs/books/tuto...moProject/src/components/TableRenderDemo.java
    >


    You did try running that code, didn't you? It seems to
    behave exactly as you describe you want it to. (Except
    the color is white).

    >This is because the JScrollPane resizes itself, to fit the size of the
    >table, but I want it not to resize like that if the table is smaller
    >then the Panel, so there will be a blank space between the last table
    >row and the end of the JScrollPane and not between the end of the
    >JScrollPane and the end of the window.
    >
    >Does anybody knows how can I do that?


    Well.. you could use the above linked code, that works,
    or change it one line at a time to your needs, and post
    the result of the first change that stops acting as you
    expect.

    (I suspect it is the layouts - or lack of them - that
    are used in the code. But only the code will tell
    the tale.)

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200706/1
     
    Andrew Thompson, Jun 16, 2007
    #2
    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. Mike
    Replies:
    5
    Views:
    5,040
  2. Happy Day
    Replies:
    5
    Views:
    8,211
    Rogan Dawes
    Aug 17, 2005
  3. Replies:
    3
    Views:
    1,612
    timjowers
    Jul 19, 2007
  4. yashiro

    Jscrollpane and jtable

    yashiro, May 17, 2008, in forum: Java
    Replies:
    2
    Views:
    1,948
    Jeff Higgins
    May 17, 2008
  5. Haircuts Are Important
    Replies:
    3
    Views:
    338
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page