如何设置宽度列AbstractTableModel

时间:2015-12-14 09:25:27

标签: java swing abstracttablemodel jtableheader column-width

需要帮助如何设置AbstractTableModel中的宽度列?我在我的表属性中设置了autoRsizeMode = Off,我正在尝试这个tablePriceList.getColumn(0).setWidth(400);这个代码在我使用DefaultTableModel时工作正常,但它在AbstractTableModel中不起作用, 这是我的AbstractTableModel班级:

public class ListPriceTableModel extends AbstractTableModel {
  private final List<ListPrice> price ;
  private final String[] columns ; 

  public ListPriceTableModel(List<ListPrice> ListPrice){
    super();
    price = ListPrice ;
    columns = new String[]{"Nomor","Kode Voicher","Description","Provider", "Nominal", "Sales Price"};
  }
  // Number of column of your table
  @Override
  public int getColumnCount() {
    return columns.length ;
  }
  // Number of row of your table
  public int getRowsCount() {
    return price.size();
  }
  // The object to render in a cell
  @Override
  public Object getValueAt(int row, int col) {
    ListPrice club = price.get(row);
    switch(col) {
      case 0: return club.getNomor();
      case 1: return club.getKode_voucher();  
      case 2: return club.getDescription();
      case 3: return club.getNominal();
      case 4: return club.getProvider_name();
      case 5: return club.getSales_price();
      default: return null;
    }
  }

  // Optional, the name of your column
  @Override
  public String getColumnName(int col) {
    return columns[col] ;
  }
    @Override
    public int getRowCount() {
        return price.size(); 
    }

}

我有谷歌它仍然没有找到任何解决方案。

0 个答案:

没有答案