Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Need help on JTable, and change cell color... (https://www.askmehelpdesk.com/showthread.php?t=826241)

  • Jul 15, 2016, 07:43 AM
    aaks1962
    Need help on JTable, and change cell color...
    Hi,

    I got this Method from Internet to change the cell color in JTable,
    the code changes the whole column color .
    my question is : how to change the cell color if it has a negative value and leave black if it's positive.

    here the Method I copied from Internet...

    public static void setCellRenderer(JTable CustDtlsTbl) {
    TableCellRenderer cellRenderer = createCellRenderer();
    CustDtlsTbl.setDefaultRenderer(Object.class, cellRenderer);
    }
    public static TableCellRenderer createCellRenderer() {
    return new DefaultTableCellRenderer() {
    @Override
    public Component getTableCellRendererComponent(JTable CustDtlsTbl, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

    Component cell = super.getTableCellRendererComponent(CustDtlsTbl, value, isSelected, hasFocus, row, column);

    cell.setForeground(Color.RED);

    return cell;
    }
    };

    Thanks

  • All times are GMT -7. The time now is 10:54 PM.