How to modify the width of columns in a JTable?

I'm looking for a way to change the width of the columns of my Jtable. For the design I use a graphical tool, but I don't find the corresponding option.

 4
Author: Awes0meM4n, 2016-01-20

2 answers

This is the construction to do it from the Code: JTable.getColumnModel().getColumn(0).setPreferredWidth(100);

If you have an X table, you have to define all of them as JTable needs to have the sizes of all of them to function.

TableColumnModel columnModel = table.getColumnModel();

    columnModel.getColumn(0).setPreferredWidth(50);
    columnModel.getColumn(1).setPreferredWidth(150);
    columnModel.getColumn(2).setPreferredWidth(200);
    columnModel.getColumn(3).setPreferredWidth(250);
 6
Author: Angel Angel, 2016-01-20 21:36:58
  1. have a JTable: o)
  2. change the "autoResizeMode" property to OFF.
  3. right Click on the JTable and enter the "Table Contents" option.
  4. Go to "Columns" tab
  5. Select the column to which we want to set the width.
  6. change the value " Pref. Width " to the width we want.
 2
Author: JUNINHO, 2017-06-03 08:15:45