Coloring text in table cells depending on what text appears

I have a table where some entries say 'success' and others say 'failure.' I want the 'success' to appear in green and the 'failure' to appear in red.
This code doesn't work:
        model = new JTTableModel();
        JTable resultsTable = new JTable(model);
        resultsTable.setDefaultRenderer(Object.class,
                new ColorRenderer());
    public class ColorRenderer extends JLabel implements TableCellRenderer {
        public java.awt.Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus,
                int row, int column) {
            System.out.println("value " +value+ " class of value "+value.getClass().getName());
            if (value.equals("success")){
                setForeground(new Color(0,255,0));
            }else if (value.equals("failed")){
                setForeground(new Color(255,0,0));
            return this;
    }What am I doing wrong?

But lmgtfy is rude, No it isn't. Most posters are too lazy to search for themselves. There are hundreds of examples of renderers to be found in the forums here. Many times is it faster for us to point to links that have the answser rather then spend time explaining everything you have done wrong. You are not the only person we help.Then why not post the link to the Google search directly? No, lmgtfy is not about simply posting a link, it's about posting a link in a way that says, 'You're too stupid to use Google, so I'll do it for you.' Which is rude. No Duke points, sorry.
As for searching this forum, the quality of search results here is definitely poor. How many screens of results should I search to find an example of what I need? Maybe I'm spoiled by Google, or maybe they should open this forum to Google search, and make the wisdom here accumulated more available.
but if you note the time this was posted,We have no idea where you live or what time of day it is for you.Yes you do, if I set the time zone on my profile.
This is my last post on this thread. I'm not going to bicker with you.

Similar Messages

  • Color of single table cell

    Hi,
    I have created a Web Dynpro table. Now I want to set the color of a single cell depending on its value and the row number.
    Is it possible? Are there any examples or tutorials for CE 7.11?
    Thanks ahead,
    Bernd

    Ok,
    situation is as follows:
    Context:
    --> Table1 (table data source)
    attr1
    attr2
    attr3
    attr4
    In wdDoModifyView (the relevant things - short form):
    table = (IWDTable) view.createElement(IWDTable.class, "Table1");
    WDNodeInfo table_node = wdContext.getChildNode("Table1",0).getNodeInfo();               
    table.bindDataSource(table_node);
    editor = (IWDTextView) view.createElement(IWDTextView.class, editor_id);               
    column = (IWDTableColumn) view.createElement(IWDTableColumn.class, column_id);
    column.setTableCellEditor(editor);
    table.addGroupedColumn(column);
    Now I want to set the TableCellDesign of a single cell depending on its value.
    Regards, Bernd

  • Color transparency in table cells

    Hi;
    Is there any way to adjust the opacity of the background
    color of a table
    cell ?
    Thanks;
    Pat

    Thanks Murray. I'll give it a try.
    Pat
    "Murray *ACE*" <[email protected]> wrote
    in message
    news:fb44ib$6r1$[email protected]..
    > No - not background color. But you can make a PNG image
    with adjusted
    > opacity and use that image as a cell background - be
    aware that unadjusted
    > IE6 and earlier doesn't support PNG transparency. A
    google search will
    > reveal workarounds for you, though.
    >
    > --
    > Murray --- ICQ 71997575
    > Adobe Community Expert
    > (If you *MUST* email me, don't LAUGH when you do so!)
    > ==================
    >
    http://www.dreamweavermx-templates.com
    - Template Triage!
    >
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    >
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    >
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    > ==================
    >
    >
    > "Pat Jones" <[email protected]> wrote in
    message
    > news:fb447e$6cf$[email protected]..
    >> Hi;
    >>
    >> Is there any way to adjust the opacity of the
    background color of a table
    >> cell ?
    >>
    >> Thanks;
    >>
    >> Pat
    >>
    >
    >

  • Coloring of selected table cells: Ideas wanted

    Hi there,
    for a WD ABAP component to be re-used in various scenarios my customer seek the most comfortable and fency way to color table cells which have been selected first.
    I am almost sure that there is no UI Control in ABAP WD which allows the selction of cells in a grid, pane, table whatever, right?
    Most suitable would be if the cell itself can be selected and then some image within is beeing displayed or even a background color is set.
    I looked into placing a button and image in UI Pane or table/ALV cells but not 100% statisfied with it.
    Is there a better way in order to "simulate" the described requirement?
    As always, the best idea will get the point
    Regards
    Carsten

    Thanks for the tips. Both helped very much.
    I implemented the simple  Table UI because which was sufficient for us but the ALV example is very useful also.
    But related to this I have another question:
    My first the coding didn't work because my Table UI already had a (static) value assigned to it's design property.
    In this case, although I have assigned a dynamic WD_UI_CELL_DESIGN context attribute to the cellDesign property of it didn't show the color.
    Only after the Table design property was set to 'standard' the cell displayed the color.
    Does anyone know what the reason for this is?
    In my opinion any design value applied to the cellDesign property should overrie the inherited table design property. My release already is NW 7.01 so it not seems to be fixed via EhP.
    Regards
    Carsten

  • Color table cells depending on value of entry in row (UI5 & JSON)

    Hello all,
    I've stuck here a bit. There have been some discussions about how to color the cells of a table that has been bound to a JSON data model. I found some answers how to color individual cells (http://http://scn.sap.com/thread/3383698), but I have a hard time to fulfill the following requirement (rephrased for simplicity):
    Given value "a" in the first cell of a table row, color the row cells 1 - 4 in blue, and 5-7 in red.
    Given value "b" in the first cell of a table row, color the row cells 1 - 4 in yellow and 5-7 in green.
    This wouldn't be a problem with normal HTML as I could easily assign style classes to every cell, however I can't find the solution for the UI5 table.
    Any ideas?
    Thanks,
    Christian

    Hi Nishant,
    not sure if I undestand you correctly.
    When I scroll the table, the data scrolls with the table correctly, but in the "Last Name" column the formatting gets messed up.
    To solve this, you need to remove the previously added classes:
      // Approach 2
        template = new sap.ui.commons.TextView().bindProperty("text", {
                parts: [
                    {path: "***" },
                    {path: "lname" }
                formatter: function(***, lname){
                   // Remove previously added classes
                  this.removeStyleClass("cyan").removeStyleClass("yellow");
                  if(*** == "m" ){
                    <!-- approach 2 step B : Add Css style class to element -->
                    this.addStyleClass("yellow");
                  }  else  if(*** == "f" )
                       this.addStyleClass("cyan");
                  return lname ;
        oTable.addColumn(new sap.ui.table.Column({ label: "Last Name",
                template: template,
    Same for the first approach using where you have to remove the custom data instead if the class.
    This should solve the problem. (By the way this is already mentioned in this thread in my post from Mar 10, 2014 11:40 AM)
    Greeets,
    ben

  • Grep: How to fill a table cell with certain color

    I have an excel sheet with 5000 rows that needs to be formatted in Indesign.
    1. Is there a way to get a certain color fill of the cell depending on text. Lets say if the text is "apple", the cell should fill with red (and text also color red to make it disappear).
    2. How do I make two different character styles to appear in the same cell (information is tab-separeted but sometimes I would like to have 2 "paragraphs" in one cell sometimes – with that I mean two tab-delimited cells from excel to appear in ONE cell in indesign).
    Thanks in advance
    Example of what I would like to accomplish:  http://tinypic.com/r/vo4och/6

    Yes but wouldn't that make the field contain a string?
    I tried something like that, and every field I edit becomes left-justified, and String (instead of int, float which is right-justified)
    Matthew

  • How to apply different CSS styles to different table cells?

    I have an h:dataTable table and I would like to apply different CSS styles to different table cells depending on their content. If I were doing JSP I would probably have a <c:if> test on the cells, and give them a style name depending on contents, and then define the styles in a separate style sheet. Is there a way in JSF to do the equivalent? Thanks.

    mitchgart wrote:
    BalusC wrote:
    How to achieve a cell-specific style is already answered in my 1st reply of this topic.That tells how to apply a style to the text (or other content) inside a cell but not how to apply a style to the <td> as a whole. It would work for something like text font or text color but not cell border.
    I'm thinking I can mark the content somehow and then have javascript traverse the DOM, find marked content, and traverse outward to the enclosing <td>. Is there a better way?BalusC already spoke about rowClasses and columnClass attributes, I assume those are insufficient.
    The Tomahawk dataTable component has the rowStyleClass and rowStyle attributes for assigning CSS to the HTML tr tag. One is allowed to reference the row data variable when assigning values to these. However, see https://issues.apache.org/jira/browse/TOMAHAWK-523 for workarounds to bugs in some implementations.
    The Tomahawk column component has the styleClass and style attributes for assigning CSS to the HTML td tag. These also may reference the row data variable.

  • Robohelp HTML 9 hyperlinks in table cells help

    Hi,
    I'm creating a table in robohelp html 9 and adding hyperlinks in the table cells. If the hyperlink is the first word in that cell robohelp is adding styling code to the link eg <td><a href="#" style="color: #0000ff; text-decoration: underline; ">test</a></td>.
    If I add a link to the second word in a table cell the styling does not appear or even if I add a space before the link the code does not appear eg <td>&#160;<a href="#">test</a> </td>.
    The code appears when I flick between design and HTML views but it does not make any difference in which view I create the link.
    No matter how many times I delete this code is keeps coming back. Can  anyone please help me? Is there some default that gives this the styling  code?Does anyone else get this issue?
    A table with the different examples is below. It was created in design view by clicking table>insert table>OK. Links added by clicking the insert hyperlink button.
    <table style="border-collapse: separate; border-collapse: separate;" cellspacing="0"
             width="33.333%" border="1">
        <col style="width: 100%;" />
        <tr>
            <td><a href="#" style="color: #0000ff; text-decoration: underline; ">test
             that has the added code</a></td>
        </tr>
        <tr>
            <td>&#160;<a href="#">test with space in front of link</a> </td>
        </tr>
        <tr>
            <td><a href="#" style="color: #0000ff; text-decoration: underline; ">test</a></td>
        </tr>
        <tr>
            <td>A <a href="#">test</a> </td>
        </tr>
    </table>
    Thanks in advanced

    I have the same problem with those stupid links in tables - I've been working on this for HOURS and HOURS...... Based on previous experience, I assumed it must only be me and an ill-formed stylesheet. The table/link issue just came to my attention because I am in the process of changing styles/formats to a new company standard (new link color) and thought I really screwed my CSS up as I was changing things!
    My only workaround thusfar has been to rewrite some data in the tables so that text will precede the link (yes, I did).  And where I just couldn't do that, I resigned myself to the problem and forced a different color on the links (changing the #0000ff).  One plus was that RH didn't rewrite the color code once it was changed manually..... but then I realized later that I didn't consider the hover color when I did this, so I now have to go back and correct them. 
    So glad to find your post...........
    I played with the idea of adding hidden text, but was worried that the problem was really a result of an issue with my CSS and doing that wasn't the proper way to fix it.   So, without guilt, I took Rick's suggestion and added an invisible dot/period at the beginning of every link in a table, when that link is the first or only content in the td.  Did the trick!  Now the links assume my declared css style! 
    I submitted a bug report.......
    Thank you!!!

  • Change the background color in a report cell - td bgcolor

    Hi.
    I have a report in which I would like to change the background color of a table cell based on some values in the underlying query
    If Column A > Column B and Column C > 10, I want to color the background green. In my cgi , this was easy, but in apex, even if I write the query to output html, won't everything already be wrapped in the <td></td> tags? Is there any way around this?
    Thanks

    Mike ,
    With the above solution you can conditionally fill the report cell with a particular color and not the entire row set. If you want to highlight entire row, you have to do something different. Take a look at this jQuery function
    Step 1 . Download jquery http://code.jquery.com/jquery-1.4.2.min.js
    Step 2. Upload it to apex image folder using shared component.
    Step 3. In the page header put the following code
    <script src="#WORKSPACE_IMAGES#jquery-1.4.js" type="text/javascript" ></script>
    <script type="text/javascript">
    $(document).ready(function(){
         if ($('.apexir_WORKSHEET_DATA').length > 0) {
              function HighLightRows(){
                                       $("table.apexir_WORKSHEET_DATA tbody td:has(COLOR_GRAY)").siblings().addClass('greentd');
                                       $("table.apexir_WORKSHEET_DATA tbody td:has(COLOR_GRAY)").addClass('greentd');
                                       $("table.apexir_WORKSHEET_DATA tbody td:has(COLOR_GREEN)").siblings().addClass('graytd');
                                       $("table.apexir_WORKSHEET_DATA tbody td:has(COLOR_GREEN)").addClass('graytd');
         // This time out is required since after the report is refreshed via AJAX,
                                  setTimeout(function(){HighLightRows();},1000);
         }//if
    HighLightRows();
    </script>
    <style type="text/css">
    .apexir_WORKSHEET_DATA td.greentd
    background-color: green !important;
    .apexir_WORKSHEET_DATA td.graytd
    background-color: gray !important;
    </style>
    Step 4. Change the SQL Query to
    SELECT
         SALE_DATE
         ,PRODUCT_NAME
         ,PRODUCT_ID
         , CASE WHEN SALE_DATE > ADD_MONTHS(SYSDATE,-2) THEN
                     '<COLOR_GREEN>&#38;nbsp;</COLOR_GREEN>'
              ELSE
                      '<COLOR_GRAY>&#38;nbsp;</COLOR_GRAY>'
         PRODUCT_NAME_COLOR
    FROM SALES;
    Step 5. Make this new column PRODUCT_NAME_COLOR visible and in the column heading u can just put &#38;nbsp;.
    As long as this column will be available for display you will see the conditional highlighting.Thanks,
    Manish

  • Semi-transparent table cell

    I know that table cells can be filled with a color or not have a fill (in which case they are transparent. However, is it possible to have a semi-transparent color in a table cell. I'm not referring to a tint, but a color that you can see through to objects that are underneath it.

    Hi Jay,
    The only way I can think of is by cheating, you could put a transparent rectangle shape into the actual cell, make sure you set the cell insets to 0 though. However if you want text in the cell as well this text will be transparent.

  • Theme Editor: where to change backgroundcolor of editable table cells?

    Hi all,
    I need to change the color of an editable table cell.
    I navigated to the theme editor --> tables.There is a section "Editable Tables". The preview shows an example with three columns and tree rows. I want to change the backgroundcolor of the cell in the first row, third column (in SAP standard it is lightgrey).
    The backgroundcolor of the rows beneath can be changed in section "Selected Cells", the backgroundcolor of the first two columns in the first row can be changed by "Background Color of Standard Table Cell" but I can't find the field where I can change the color of the last cell.
    Best regards,
    Sandra

    Hi,
    The blue color come from your definitions on "Labels and Fields" to read-only color of input field.
    Regards,
    F.F

  • Table cell selection border

    hi,
    how can you find out the default color of the table cell renderer border?
    when you select a cell in a JTable, there's (by default) a thin border drawn around it. since i use my own renderer for some columns, i need to find out the color of this border (it is differnt for different look & feels).
    thanksout the default

    you were right. thank you.
    just one more thing: where can i find the names of all those properties that the UIManager uses? like the one you used "Table.focusCellHighlightBorder"...

  • Fill table cells with color % depending on cell content

    Hi.
    I'm working on a document with a lot of tables filled with percentages. The tables are originally on a Word document and the table cells are tinted according to their content: a value of 20% on the cell corresponds to a tint of 20%. This is done automatically on the Word document through a conditional formatting option that applies a graded color scale. Is there any way to do this in InDesign? I tried placing the tables and tried all options, but the color is not imported. Perhaps a script or a GREP style?
    Thank you.

    Conditional formatting in Word is done via formula, but in Excel it is handled more "on the surface" and Excel's conditional formatting carries into InDesign nicely via Place or Paste. It could be worth considering moving those tables into Excel.
    InDesign doesn't do this kind of formatting as a native function, but it couldn't hurt to ask about possible scripted solutions in the Scripting Forum.

  • Highlighting text in a table cell

    Im trying to get text in a table have it background shaded a different colour to the rest of the table cell but it doesnt work. No exceptions are thrown does anyone have any idea.
    public Component getTableCellRendererComponent(JTable table,
            Object value,
            boolean isSelected,
            boolean hasFocus,
            int row,
            int column)
            setFont(table.getFont());     
            this.setText(value));
            this.selectAll();
            this.setSelectionColor(new Color(0,0,255,100);
            return this;
        }

    The answer is similar to what someone else asked recently for highlighting text in a JFormattedTextField cell.
    class MyFocusListener extends FocusAdapter
    public void focusGained(FocusEvent e)
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    selectAll();
    Put that in your cell editor or its base class. You can change the color or whatever you want. I think the problem is a timing thing where normal focus processing is interrupting your changes. So give the focus processing time to run with this Runnable triggering your processing to occur on the Awt thread (as is proper) after the system is doing whatever it wants to do. Let us know if it works for you.

  • Table cell with 2 colors

    Hi Guys,
    I have a JTable which I need its cells to have 2 colors (indicating different type of data for the same cell). I could not find a way to do this. Anyone can help me out here?
    Thanks in advance
    Eman

    PhHein wrote:
    eman_c wrote:
    Hi,
    I already checked that page, and as far as i understood (and please correct me if I am wrong) the renderer lets you control one cell (which is great) but one cell can be applied with one ForGround color. What I needed is that in the same cell, part of the data is colored red for example and the other in green. If it is indeed possible using cell render, could you please explain how?
    Thanks again
    EmanSorry, I don't think it is possible at all to have different background colors in one cell. But you could however set different text colors in the same cell by using html.Err...
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.util.*;
    import java.util.regex.*;
    import java.text.*;
    public class ShadeCellDependingOnValue extends JPanel
        static final Object[][] tableData =
            {1, new Double(10.0)},
            {2, new Double(20.0)},
            {3, new Double(50.0)},
            {4, new Double(10.0)},
            {5, new Double(95.0)},
            {6, new Double(60.0)},
        static final Object[] headers =
            "One",
            "Two",
        public ShadeCellDependingOnValue() throws Exception
            super(new BorderLayout());
            final DefaultTableModel model = new DefaultTableModel(tableData, headers);
            final JTable table = new JTable(model);
            table.getColumnModel().getColumn(1).setCellRenderer( new LocalCellRenderer(120.0));
            add(table);
            add(table.getTableHeader(), BorderLayout.NORTH);
        public class LocalCellRenderer extends DefaultTableCellRenderer
            private double v = 0.0;
            private double maxV;
            private final JPanel renderer = new JPanel(new GridLayout(1,0))
                public void paintComponent(Graphics g)
                    super.paintComponent(g);
                    g.setColor(Color.CYAN);
                    int w = (int)(getWidth() * v / maxV + 0.5);
                    int h = getHeight();
                    g.fillRect(0, 0, w, h);
                    g.drawRect(0, 0, w, h);
            private LocalCellRenderer(double maxV)
                this.maxV = maxV;
                renderer.add(this);
                renderer.setOpaque(true);
                renderer.setBackground(Color.YELLOW);
                renderer.setBorder(null);
                setOpaque(false);
                setHorizontalAlignment(JLabel.CENTER);
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col)
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
                if (value instanceof Double)
                    v = ((Double)value).doubleValue();
                return renderer;
        public static void main(String[] args) throws Exception
            final JFrame frame = new JFrame("Fred120");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(new ShadeCellDependingOnValue());
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
    }

Maybe you are looking for