Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I resize table columns individually using Netbean's GUI Builder?

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?

like image 497
akbiggs Avatar asked Feb 12 '11 21:02

akbiggs


People also ask

How do I resize a table in Netbeans?

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

How do you resize column width in a table?

Change column width To change the width to a specific measurement, click a cell in the column that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Column Width box, and then specify the options you want.

How do you change the size of a table in Java?

For a simple solution you can use: width = Math. max (comp. getPreferredSize().

How do I change layout space in Netbeans?

Right-click one of the buttons and choose Edit Layout Space from the popup menu. The Edit Layout Space dialog box is displayed.


2 Answers

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.

like image 187
gigadot Avatar answered Nov 01 '22 11:11

gigadot


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.
like image 22
RaKXeR Avatar answered Nov 01 '22 13:11

RaKXeR