Jtable arranging

Hi.

I have to questions:

1? I've designed a Jtable in NetBeans, if the table takes few rows of data, there's an extra space after the last row that stays visible.

How can i resize the table height so it fits by the number of rows ?

2?br>The table has to columns, each one gets 50% the table size.

How can i set the size each column must have ?

Thank you.

[399 byte] By [noe.rochaa] at [2007-11-27 9:47:41]
# 1

Resizing the rows might not be such a good idea. You could rather make the viewport background match that of the table so it doesnt seem that there is a trailing space.

JScrollPane pane = new JScrollPane(yourTable);

pane.getViewport().setBackground(Color.white);

For your second problem you need to turn of column auto resizing and then resize each column using the table column model

table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

DefaultTableColumnModel cmodel = (DefaultTableColumnModel)table.getColumnModel();

cmodel.getColumn(0).setPreferredWidth(100);

ICE

icewalker2ga at 2007-7-13 0:00:19 > top of Java-index,Desktop,Core GUI APIs...
# 2

Not quite the results i was hoping.

Changing the column size works, but if i stretch any column outside the table i get an horizontal bar.

And when setting the background color to the viewport i can't see any row.

PS: Columns size now work like i want with this:

TableColumn col = table.getColumnModel().getColumn(vColIndex);

col.setMinWidth(width);

col.setMaxWidth(width);

col.setPreferredWidth(width);

Now all i need is to get rid of the extra table space after the last row.

Message was edited by:

noe.rocha

noe.rochaa at 2007-7-13 0:00:19 > top of Java-index,Desktop,Core GUI APIs...
# 3
> Now all i need is to get rid of the extra table space after the last row.table.setPreferredScrollableViewportSize(table.getPreferredSize());
camickra at 2007-7-13 0:00:19 > top of Java-index,Desktop,Core GUI APIs...
# 4

> > Now all i need is to get rid of the extra table

> space after the last row.

> table.setPreferredScrollableViewportSize(table.g

> etPreferredSize());

This is getting on my nerves, i have tryed that and this:

int width = this.FILENAMES.getWidth();

int n_rows= this.FILENAMES.getRowCount();

int height = this.FILENAMES.getRowHeight() * n_rows;

//this.FILENAMES.setSize(width, height);

this.FILENAMES.setPreferredScrollableViewportSize(new java.awt.Dimension(width, height));

and the table doesn't want to shrink to the last row.

noe.rochaa at 2007-7-13 0:00:19 > top of Java-index,Desktop,Core GUI APIs...
# 5
> This is getting on my nerves, i have tryed that and this:But that is not the code I gave you. Why did you make it more complicated than it needs to be?Works fine for me in this simple example: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637504
camickra at 2007-7-13 0:00:20 > top of Java-index,Desktop,Core GUI APIs...
# 6
I forgot to say i tryed your code too, but with no sucess.then i tryed that code too.
noe.rochaa at 2007-7-13 0:00:20 > top of Java-index,Desktop,Core GUI APIs...