Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Changing cell Color is resetting cell default... (https://www.askmehelpdesk.com/showthread.php?t=826294)

  • Jul 18, 2016, 07:23 AM
    aaks1962
    Changing cell Color is resetting cell default...
    Hi, I've a JTable and one of the Columns is defined as double, the data inside the cells of that column is aligned Right automatically. When I change the cell color to "red" if the value is less than certain value, then all cells are left aligned!! How can I keep the default settings of the column as it is even after changing the color of the cells? this is the methods I got from some websites on 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); if ( column == 3 ){ double newValue = Double.parseDouble(value.toString()); if ( newValue < 100 ){ cell.setForeground(Color.RED); } } else { cell.setForeground(Color.BLACK); } return cell; } }; } Thanks

  • All times are GMT -7. The time now is 07:01 PM.