Ask Experts Questions for FREE Help !
Ask
    aaks1962's Avatar
    aaks1962 Posts: 2, Reputation: 1
    New Member
     
    #1

    Jul 15, 2016, 07:43 AM
    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

Check out some similar questions!

Cell Border Color Incorrect In FF [ 1 Answers ]

Hi. In internet explorer I get what I want as follows: http://img264.imageshack.us/img264/2254/iepd4.png But in Firefox I get: http://img261.imageshack.us/img261/7241/ffjg5.png

Cell Border Color: Firefox vs. IE. [ 4 Answers ]

Here I've colored the cell border Red (FF0000). In IE it is the candy apple red that I want it to be But In FF, it's an odd two toned color and includes a "bevel". I love the bevel that FF shows but hate the color. Anyone know how I can have the best of both worlds?: 1. Have it appear...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.