JTable column width

preserve current column with after 'fireTableChanged' method

Page 1 of 1

1 Replies - 5156 Views - Last Post: 12 April 2007 - 09:39 AM Rate Topic: -----

#1 gyron  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 09-January 07

JTable column width

Posted 12 April 2007 - 07:41 AM

I have a JTable with a number of columns such that a horizontal scroll bar is necessary ( i have managed to have that no problem). Now what happens is that when the user is viewing the data in that table and then refreshes that data, the table columns are then resized when this method is called: -

public void executeQuery(String strSQL){
	  int i,max;
	  Vector rowData;
	  try
	  {
		  data = new Vector();
		  names = new Vector();
		  resultSet = statement.executeQuery(strSQL);
		  metaData = resultSet.getMetaData();
		  max =  metaData.getColumnCount();
		  //get the column names
		  for(i=0;i< max;i++){
			  //adjust for meta data index start at 1
			  names.addElement(metaData.getColumnLabel(i+1));
		  }
		  //load the data
		  while (resultSet.next())
		  {
			  rowData = new Vector();
			  for (i=0;i< max;i++)
			  {
				  rowData.addElement(resultSet.getObject(i+1));
			  }
			  data.addElement(rowData);
		  }
		  fireTableChanged(null);
	  }
	  catch (Exception exp)
	  {
		  System.out.println("Error performing query: " + exp);
		  System.out.println(strSQL);
		  exp.printStackTrace();
	  }
  }1



It is most likely that the user would have manually resized the columns when viewing the previous ResultSet in the table. How do i keep the column widths as was before the above method was called?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: JTable column width

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: JTable column width

Posted 12 April 2007 - 09:39 AM

Try to fire a less aggressive event instead of tableChanged, like row or data changed or something.
I haven't looked up the exact function or event names, but as I recall similar things exist.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1