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
- have a JTable: o)
- change the "autoResizeMode" property to OFF.
- right Click on the JTable and enter the "Table Contents" option.
- Go to "Columns" tab
- Select the column to which we want to set the width.
- change the value " Pref. Width " to the width we want.
2
Author: JUNINHO, 2017-06-03 08:15:45