I read all the posted messages concerned with setting the column width of a JTable. I literally copied the posted answers just changing the JTable name but kept getting error messages for each statement that tries to set the current column width.
I simply define a JTable with 7 fixed columns whose names are passed to the DefaultTableModel. I must be missing something but... what?
I am posting just the few relevant lines. Thank you in advance for any suggestion.
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
JString[] columnNames = {"New Line Name", "Point1", "Point2", "Angle", "Parallel Line Name",
"Distance From Line", "Group"};
DefaultTableModel linesTableModel = new DefaultTableModel(null,columnNames);
JTable tblLines = new JTable(linesTableModel);
TableColumnModel colModel = tblLines.getColumnModel();
colModel.getColumn(0).setPreferredWidth(100);
colModel.getColumn(1).setPreferredWidth(50);
colModel.getColumn(2).setPreferredWidth(80);
colModel.getColumn(3).setPreferredWidth(150);
colModel.getColumn(4).setPreferredWidth(200);
colModel.getColumn(5).setPreferredWidth(100);
colModel.getColumn(6).setPreferredWidth(90);
Oracle has a helpful tutorial, Creating a GUI With Swing. Skip the Learning Swing with the NetBeans IDE section.
I went to the trouble of creating the rest of the code. Here's the GUI.
Other than the columns not wide enough for the column headers, I don't see a problem.
Here's the complete runnable code, which is what you should be including with your question.