Click to See Complete Forum and Search --> : How to set the size of a column in a Table?


cntomcom
January 8th, 2003, 03:01 AM
size or relative size

dlorde
January 8th, 2003, 05:42 AM
Get the desired TableColumn (http://java.sun.com/j2se/1.4/docs/api/javax/swing/table/TableColumn.html) and then you can set the max width, min width, preferred width, and width:TableColumn column = myTable.getColumn(foo);
// or
// TableColumn column = myTable.getColumnModel().getColumn(index);
column.setMaxWidth(...);
column.setMinWidth(...);
column.setWidth(...);
column.setPreferredWidth(...);
// etc.

There are no 'accidents', only human errors and failings...

cntomcom
January 8th, 2003, 10:59 AM
foo stands for what??>

Goodz13
January 8th, 2003, 11:12 AM
The identifier object for your Column.
Which one getColumn should return.

dlorde
January 8th, 2003, 01:26 PM
cntomcom - the first thing you should do when you have a question about a class method is look at the JavaDoc for that class method, e.g. JTable.getColumn(...) (http://java.sun.com/j2se/1.4/docs/api/javax/swing/JTable.html#getColumn(java.lang.Object)). In some cases (like this one), it may still not be clear what is meant, so you follow (where possible) the clues to related classes, e.g. TableColumn (http://java.sun.com/j2se/1.4/docs/api/javax/swing/table/TableColumn.html). A little persistence and common sense will generally lead you to an explanation, e.g. TableColumn.getIdentifier() (http://java.sun.com/j2se/1.4/docs/api/javax/swing/table/TableColumn.html#getIdentifier()).

This process is absolutely essential if you want to be a successful Java programmer, so it is important that you become familiar with the JavaDocs. Knowing how and where to find the information you need is probably the single most important aspect of practical programming.

There's no doubt that cowardice can be a life saver...