https://github.com/teerjk/VarSifter
Raw File
Tip revision: 7e57e5857b08f5253f28e96477fc211f67a0ffea authored by Jamie K. Teer on 27 April 2020, 14:42:41 UTC
-Documentation updates to point to github.
Tip revision: 7e57e58
FloatScoreRenderer.java
import java.text.NumberFormat;
import javax.swing.*;
import javax.swing.table.*;

/**
*   Sets a larger precision for Float values, sets center alignment
*   @author Jamie K. Teer
*/
public class FloatScoreRenderer extends DefaultTableCellRenderer {
    
    private NumberFormat f;

    /**
    *   Constructor
    *
    *   @param precision The number of decimal places to display
    */
    public FloatScoreRenderer(int precision) { 
        super(); 
        f = NumberFormat.getNumberInstance();
        f.setMaximumFractionDigits(precision);
        f.setMinimumFractionDigits(precision);
    
    }

    /**
    *   Sets text of cell with correct precision
    *
    *   @param val The stored value of the cell
    */
    @Override
    public void setValue(Object val) {
        float nv = ((Float)val).floatValue();
        setText(f.format(nv));
        setHorizontalAlignment(SwingConstants.RIGHT);
    }
}
back to top