Adjust column widths of JTable

Discussion in 'Java' started by Gerhard Rapp, Jul 18, 2003.

  1. Gerhard Rapp

    Gerhard Rapp Guest

    Hi all.

    I try to automatically adjust the column widths of a JTable according to
    their content. My ideas were (1) to search the longest entry for each column
    by going through all entries. (Which is pretty slow for long tables) And (2)
    to adapt the getValueAt function to detect and store the longest entry for
    each column, so I can set these values when the table is displayed the first
    time. Btw. which event handler will I have to use here?

    I guess some of you have faced this problem before. What are your solutions?

    In this context I have another question? If the sum of the column widths is
    greater than the width of the table's scroll pane one has to set the
    autoresize strategy property of the table to OFF. If the total width is less
    than the scroll panes' width one gets an annoying border around the table.
    How can I prevent this? Apart from adding a dummy column at the right. And
    what about the rows?

    Thanks
    Gerhard
     
    Gerhard Rapp, Jul 18, 2003
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.