Reputation:
I'm new to using JAVA.. How do i set individual column widths of a JTable in netbeans?
Upvotes: 0
Views: 4875
Reputation: 7414
Is this about using the Swing GUI builder (formerly Project Matisse) in NetBeans, or about creating a table by hand while using the NetBeans IDE?
JTable's TableColumnModel's TableColumn column widths are generally controlled by setting it's preferred width. Depending on the layout you may want to modify the minWidth and maxWidth fields of the TableColumn.
If you're using the Swing GUI builder you could call this after initComponents() in the containing panel's constructor, or if you're using static data in design mode you can right-click the table, choose Table Contents, and set the widths as you add columns using the Customizer Dialog. There is also the option to "Customize Code" in design mode to modify pieces of the IDE managed initComponents method.
Setting the widths by hand after initComponents() may be the easiest and least magical initially.
public MyPanel() {
initComponents();
TableColumn col = table.getColumnModel().getColumn(0);
col.setPreferredWidth(100);
}
Note: I'm referencing NetBeans IDE 6.8 as I answered this, menu items and dialogs may differ.
Upvotes: 1