0

Java Bean バインディングを使用して Jtable をバインドし、API は以下に示すように 0 または 0.0 などの整数または浮動小数点値のデフォルト値を提供します。対応するデフォルト値を避け、最後のセル値を除いてセルを空に設定したいと思います.

1        WW     88.0        88.0      1021021       340.0       
4        TT     55.0        55.0      1021021       340.0       
5        PP     66.0        66.0      1021021       340.0

                0            0          0           1020

2        gg     66.0        66.0      1021022       320.0       
3        LL     658.0       652.0     1021022       320.0

               0            0          0             640

テーブルは次のようになります。

1        WW     88.0        88.0      1021021       340.0       
4        TT     55.0        55.0      1021021       340.0       
5        PP     66.0        66.0      1021021       340.0

                                                    1020

2        gg     66.0        66.0      1021022       320.0       
3        LL     658.0       652.0     1021022       320.0

                                                     640

この問題を解決するためのより良い方法を提案できる人なら誰でも、それは素晴らしいことであり、事前に感謝します.

4

3 に答える 3

1

この問題ステートメントの最初の列は空白だと思います

メソッドをオーバーライドできますTableModel getValueAt(int row, int column)

@Override
public Object getValueAt(int row, int column){
  Object value = super.getValueAt(row, column);//Or get it from the Vector defined
  if(column == 2) {//Demo for the third column do same for other columns
    //Check the value in the first column if it is coming null
    if (null == getValueAt(row, 0) || getValueAt(row, 0) == ""){
      return null; // null means blank cell
    }
  }
  return value;
}
于 2012-05-01T18:42:02.450 に答える
1

TableModelこれはで、特にgetValueAt(int row, int column)メソッドを使用して行うことをお勧めします。何かのようなもの:

public Object getValueAt(int rowIndex, int columnIndex){
  Object cellValue = // get your values out of your Beans...
  if (cellValue==0 && columnIndex!=LAST_COLUMN_INDEX){
    return null;
  }
  return cellValue;
}
于 2012-05-01T18:27:35.010 に答える
0

Jtable Bean バインディングを使用し、beansbinding-1.2.1.jar API を自動バインディングに使用していました。beansbinding-1.2.1.jar ソースをダウンロードし、クラスに関連する変更を加えました

/org.jdesktop.swingbinding.JTableBinding.java

containing the class BindingTableModel.java which implements the TableModel and I overridden the method as per the suggestions of above two friends and thanks to all...

@オーバーライド

public Object getValueAt(int row, int column) {
            Object value = valueAt(row, column);

            if (value != null
                    && (value.toString().equals("0") || value.toString()
                            .equals("0.0")|| value.toString().equals("default"))) {
                return null;
            }

            return value;
        }
于 2012-05-02T11:29:46.410 に答える