The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.table  [62 examples] > Columns  [11 examples]

e919. Locking the Width of a Column in a JTable Component

This example demonstrates how to set the width of a column and prevent it from being resized by the user.
    int rows = 3;
    int cols = 3;
    JTable table = new JTable(rows, cols);
    
    // Add data here
    
    // Lock the second column of the table to be 100 pixels wide
    int vColIndex = 1;
    int width = 100;
    TableColumn col = table.getColumnModel().getColumn(vColIndex);
    col.setMinWidth(width);
    col.setMaxWidth(width);
    col.setPreferredWidth(width);

 Related Examples
e915. Converting a Column Index Between the View and Model in a JTable Component
e916. Enumerating the Columns in a JTable Component
e917. Setting the Width of a Column in a JTable Component
e918. Setting the Column Resize Mode of a JTable Component
e920. Appending a Column to a JTable Component
e921. Inserting a Column in a JTable Component
e922. Removing a Column from a JTable Component
e923. Moving a Column in a JTable Component
e924. Allowing the User to Move a Column in a JTable Component
e925. Allowing the User to Resize a Column in a JTable Component

See also: Cells    Column Heads    Editing    Events    Layout    Rows    Scrolling    Selection    Sorting    Table Model    Tool Tips   


© 2002 Addison-Wesley.