🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12090

Re: JTable Columns Resize

#12090
From: Einar Kristinsson
Date: Mon, 22 Feb 1999 00:00
46 lines
1702 bytes
"J. Leroy" wrote:
> 
> Hi !
> What do I have to do to keep my columns size constant?
> I don't want to let the user resize the columns width.
> 
> Thanks.
> J. Leroy
Well, here are two things you can do:

------ one 
..
....
      	String columns = { "col1", "col2","col3" } 
      	DefaultTableModel dtm = new DefaultTableModel(colums,0);
      	JTable jt  = new JTable (dtm);
     	jt.getTableHeader().setResizingAllowed(false);
//      	jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//	jt.getTableHeader().setReorderingAllowed(false);
...
.

------ Two.
..
....
      String columns = { "col1", "col2","col3" } 
      DefaultTableModel dtm = new DefaultTableModel(colums,0);
      JTable jt  = new JTable (dtm);

      int [] widths = {72,32,4 };
      TableColumnModel tcm = jt.getColumnModel();
      TableColumn col;
	for (int i = 0; i < widths.length-1; i++) { // freezea all table
columns at a specified width
		col = tcm.getColumn(i);
		col.setMinWidth(widths[i]);
		col.setWidth(widths[i]);
		col.setPreferredWidth(widths[i]);
		col.setMaxWidth(widths[i]);
	}
...
..
------
OK 

Einar S. Krist.
Technical Details
Message-ID: <36D1BB33.44D09F60@decode.is>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7asbpl$s5s6@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,c863e566a0d9ba41
X-Google-Attributes: gid111d45,public
From: Einar Kristinsson <einar@decode.is>
Subject: Re: JTable Columns Resize
Date: 1999/02/22
Message-ID: <36D1BB33.44D09F60@decode.is>
X-Deja-AN: 447205946
Content-Transfer-Encoding: 7bit
References: <7asbpl$s5s6@forums.borland.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing