Code example for JLabel

Methods: setHorizontalAlignment

0
        } else if (value instanceof Integer) {
            value = humanReadableByteCount((Integer) value);
        } 
         
        JLabel c = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        c.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        return c;
    } 
     
    private String humanReadableByteCount(long bytes) {
        int unit = si ? 1000 : 1024;
        if (bytes < unit) {
            return bytes + " B";
        } 
        int exp = (int) (Math.log(bytes) / Math.log(unit));
        String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
        return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
    } 
} 
Contextual code suggestions in your IDE  Get Codota for Java