8

In making a quick mockup of a project's end design using Netbeans' GUI Builder, I've run into a problem with the options given to me for the Table object. It seems that I can't resize columns individually, only the whole table. Am I wrong, and is there a way to resize columns using the GUI Builder? If not, could I accomplish this using Swing code? How?

akbiggs
  • 34,001
  • 6
  • 25
  • 36

2 Answers2

11

SInce the default JColumnModel created by Netbeans GUI builder is hidden and cannot be customized in Properties plalette, you will have to do it programatically.

Go the `Source view' (there is a small button above the editor pane to switch between Source View and Design View) and put the following code in the constructor

/** Creates new form NewJFrame */
public NewJFrame() {
    initComponents();
    // Insert this line into your code
    jTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
}

Fore more details, read here or google for "jtable set column size".

Here is another useful information.

Community
  • 1
  • 1
gigadot
  • 8,879
  • 7
  • 35
  • 51
  • It works!! Thanks. The only thing that had me confused for a bit was that the width changes don't show up in Design view or in Preview mode, only when you run the actual code. – akbiggs Feb 13 '11 at 03:22
  • Yes, that's because it a custom code. Netbeans cannot interpret what it does not generate. – gigadot Feb 13 '11 at 03:24
6

For anyone still looking for the answer that finds this post, the selected answer is not the correct way to do it from the Netbeans GUI.

As said in one of the answers here (by Heater Buch), in order to change the column width:

  1. In design view, right-click over the table;
  2. Choose "Table Contents ..." and a Customizer Dialog will appear.
  3. Click the "Columns" tab, and there you will be able to set several properties, including the preferred / minimum / maximum width.
RaKXeR
  • 152
  • 2
  • 16