Java – how to use netbean’s GUI builder to individually resize table columns?

When using NetBeans GUI builder to quickly simulate the final design of the project, I encountered a problem with the options provided to me for the table object It seems that I can't resize the column alone, I can only resize the whole table I'm wrong. Is there any way to use GUI builder to resize columns? If not, can I do this using swing code? What about?

Solution

The default jccolumnmodel created by the NetBeans GUI builder is hidden and cannot be customized in the property platette. You must do this programmatically

Go to source view (there is a small button at the top of 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);
}

For more information, read here or Google for "JTable set column size"

Here is another useful piece of information

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>