1 Replies - 3559 Views - Last Post: 29 March 2008 - 09:50 AM Rate Topic: -----

#1 fsloke  Icon User is offline

  • D.I.C Regular

Reputation: 25
  • View blog
  • Posts: 412
  • Joined: 19-December 07

How to change Tabel Column width?

Posted 29 March 2008 - 02:26 AM

My Table display the column with equal length....

How to change Tabel Column width?

Thank...
Is This A Good Question/Topic? 0
  • +

Replies To: How to change Tabel Column width?

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4189
  • View blog
  • Posts: 11,864
  • Joined: 18-April 07

Re: How to change Tabel Column width?

Posted 29 March 2008 - 09:50 AM

If you are referring to a JTable you must first disable autoResizeMode..

JTable table = new JTable(rows, cols);
    
// Disable auto resizing
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);



Then you need to get a reference to the column to adjust and set its preferred width...

// Get first column from the column model
TableColumn col = table.getColumnModel().getColumn(0);

// Set its preferred width to 200
col.setPreferredWidth(200);



That should get you up and running with custom sizes for the columns. Enjoy!

"At DIC we be column adjusting code ninjas!" :snap:

This post has been edited by Martyr2: 29 March 2008 - 09:51 AM

Was This Post Helpful? 1

Page 1 of 1