• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable cells way to big !!!

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys : Im creating a JTable using the
default table model but all the cells
are absolutely enormous , even if they
only have a single string of 4 or 5 characters.


Im not really doing anything fancy in the UI, just setting the model :

setModel(new DefaultTableModel ( ){

// These simple methods return basic information about the table
public int getColumnCount()
{
return names.length;
}

public int getRowCount() {
return beansVector.size();
}

public String getColumnName(int column)
{
return names[column]+"";
}

/**
* This method returns the value that appears at the specified row and
* column of the table
*/
public Object getValueAt(int row, int column)
{
try
{
String value = BeanUtils.getProperty(beansVector.get(row), names[column]+"") +"" .trim() ;
return value;
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
});
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for not finishing the last post...

Any suggestions ? By the way ... the problem may be
related to the fact that I dynamically remove columns in the table - so the existing columns are actually spanning 4 columns worth of space... But shouldnt the jtable handle this sort of
preferred size refactoring for me ?

Thanks !

Jay
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to take care to remove both the data from the model and the column from the table. Removing a Column from a JTable Component.
 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi : The removed columns are not showing up in the view - its just that the table columns which have not been removed are "filling" up more space than necessary. Im using an extension of the DefaultTableModel. Any ideas ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!