JTable set single row color

I have alternating colors for my jtable, and when a row is selected i pop up another window and clear the selection. i want to change the color of all selected rows, but if i dont clear the selection, it doesn't allow me to re-open the same record because of the way the selectionListener works. so basically i dont want to mark a row as selected, i jus want to change its color. anyone know how to do this?

looks promising.. i'm going to give it a shot. why dont they just have a method like.. table.setRowColor (rowIndex), because im implementing a selectionlistener, so i already know the rowIndex that was selected, jus have to change its color. maybe coz that would be tooo easy lol. thanks

Similar Messages

  • Setting alternate row color of DataGridColumn

    Is there a way to set alternate row color of a
    DataGridColumn? I need to set different alternating row color to
    different DataGridColumn.

    Please Check this example
    http://www.flex4ex.com/?p=9

  • Is there a Terminal command to set alternate row colors in Mail?

    I'd like to enable the alternate row colors in the message list, but the only way I can find to do it requires Developer tools to be installed.
    Not bad for my Mac, but it seems a bit of a workload for the other 19 Macs in the office. There's nothing in Onyx or Secrets that'll do this.
    Here's what I found on the web: http://pjkh.com/articles/2007/10/08/alternating-row-colors-in-apple-mail
    There's a plug-in called WideMail which I'm using but it doesn't seem 100% stable.
    Thanks

    Just do the hack once and copy that version of the Mail.app application (or just the MessageViewerContents.nib file) to the other machines. Just make sure that they are running exactly the same version of Mail and MacOS X. This hack will probably not work in Snow Leopard, by the way.

  • JTable - set Selected row?

    How do you set the current selected row and highlight it?

    You use the public ListSelectionModel getSelectionModel()
    method of your JTable. Once you have the ListSelectionModel you can use public void setSelectionInterval(int index0, int index1) to select one or more rows.
    Depending on your selection mode you may or may not be able to select multiple rows. This is set by the ListSelectionModel's public int getSelectionMode() and public int setSelectionMode(int SelectionMode) methods.
    Hope it helps.
    Greg

  • Alternting row color on HEADERS

    I cannot figure out how to alternate the row color on the header columns. Personally I find it annoying if the header column is all the same color, but the table rows alternate. I find it hard to follow across the columns since I have several columns set at headers. I tried manually setting the row color, but on a sort, the colored rows are all jumbled and don't match the alternating rows on the data.

    Hi k,
    The short answer is that it can't be done.
    The longer one is that it can, but the process is tedious.
    The three images below are of the same table. The table was sorted and renamed to indicate that sort, and screen shots of the first two sorts pasted into the document before grabbing the image of all three states.
    Row 1 is a header row, and does not enter into the sort.
    Column A is a header column. When the table is formatted for alternate row colours the colours apply only to the Standard cells (columns B and C of the initial table (plus the added columns D and E).
    The cells in column A require a Conditional Formatting rule to change their fill colour to match the alternate row colour under a specific condition. One of the conditions available is that the text in the cell matches the text in another specific cell.
    The cells in columns D and E are used to set up that condition. The In the final table, D and E may be hidden.
    The formula in D is:   =MOD(ROW(),2)
    As can be seen, this places a 0 in 'even' rows and a 1 in 'odd rows.
    The formula in E is:   =IF(D>0,A,"")
    For 'odd' rows, where D contains a 1, this copies the contents of the cell on the same row in column A into column E. For 'even' rows it places the empty string into column E.
    Both formulas are filled down through all standard rows of columns D and E.
    Note that the two formulas can be combined into one:   =IF(MOD(ROW(),2>0,A,"")
    Idf the single formula is used, the steps below assume it is entered in E2 and filled down the rest of column E.
    You will need one column 'E' for each header column you want to format, with the formula in each adjusted to pick up the contents of column A, B, C, etc.
    Now comes the tedious part. The Conditional Formatting rules compare the contents of the cell to a fixed value or to the contents of a specific other cell. Unlike formulas, they to not self-adjust if we use Fill Down.
    But we can save a few steps by choosing the conditional fill colour for all cells at once, then editing the reference cell for each individually.
    • Select all of the cells in column A (and the other header columns to which you want to apply conditional formatting).
    • Open the Cell Format Inspector and click Show Rules...
    • In the dialogue that opens, use the popup to choose "Text is"
    • Click the icon at the right end of the box that appears, then click cell E2 (the first non-header cell in column E) on the table.
    • Click Edit.
    • Click the Fill color well that appears, then choose the conditional fill colour to match the alternate row colour. (Hint: Use a colour from the color palette—easier to match)
    • Click Done to confirm the choices.
    •Click away from the selected cells to release the selection, then click on A3 to select just that cell.
    Repeat the following until you're through the column.
    • Click on the E2 reference in the box beside "Text is" to select it.
    • On the table, click on the cell to be referenced (it will be the one below the cell indicated by a blue outline). The E2 reference in the rule will change to the new cell.
    • Press return to confirm the new selection.
    • Press return again to move down to the next cell.
    Repeat.
    It works, but it certainly ain't elegant!
    You might also consider going to the Application menu (in Numbers, the "Numbers" menu), choosing Provide Numbers Feedback, and making a request that the alternating row colour feature be enhanced to apply to alternate row in a header column as well as to standard cells. Be prepared to wait, though, at least until the next full version of Numbers is released.
    Regards,
    Barry

  • How do you set the font color for a specific entire row inside a JTable?

    How do you set the font color for a specific entire row inside a JTable?
    I want to change the font color for only a couple of rows inside a JTable.
    I've seen some ways to possibly do this with an individual cell.
    Clarification on changing the font color in an individual cell would be helpful too if
    there is no easy way to do this for a row.

    hai,
    Try out with this piece of code.Create your table and assign the renderer to each column in the table.
    CellColorRenderer m_CellColorRenderer = new CellColorRenderer();
    for(int i=0;i<your_JTable.getColumnCount();i++)
    your_JTable.getColumnModel().getColumn(i).setCellRenderer(m_CellColorRenderer);
    class CellColorRenderer extends JLabel implements TableCellRenderer
    CellColorRenderer()     
    setOpaque(true);     
    setHorizontalAlignment(LEFT);
    setVerticalAlignment(CENTER);
    setBackground(Color.white);
    setForeground(Color.black);
    protected void setValue(Object value)
         setText((value == null) ? "" : value.toString());
    public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected, boolean hasFocus, int row,int column)
         if(isSelected == true)
              setForeground(Color.red);
         else
              setForeground(Color.black);
         setValue(value);
         return this;
    regards,
    bala

  • URGENT - Change color for a set of rows in JTable

    Hello all,
    How can i set color for a particular set of row which are all having same values in a cell. If any other rows contains same value that should also be in different color.
    Example:
    I have 10 rows containing itemcode and taxes in JTable.
    1st, 2nd and 4 th row contains same value of Taxes -- It should be in a set of color. red
    6th and 8th row containing same value of Taxes -- it should be in a set of color blue
    other are in normal color. Kindly send the coding for the above. Advance thanks.
    Regards,
    N.A. Ramasubramani / Chennai.

    Hi,
    Here is how I do it... create a Vector of Vector or an array[row][col] containing colors for every cell (row,col). Create a custom Cell renderer in which you pass the color data variable. Then in the renderer you get the Row and Col and set the appropriated color for the background.
    JRG

  • Setting Row Color of the JTable

    Hi,
    I wanted to set the first row and first column of the JTable .
    Can anybody help me in this? I read CellRendering but didn't understood when getTableCellRendererComponent(...) method get called and how it works.
    I realy appreciate if anybody explains me.
    Thanks,
    Padmashree

    Hi,
    If my understading is correct, You are trying to set the color of the first column of the first row.
    "Renderer" returns the component used for drawing the cell. It applies for all the cell. Method called
    "GetTableCellRendererComponent" is used to configure the renderer appropriately before drawing.
    So the following parameters are provided to acheive it.
    table - the JTable that is asking the renderer to draw; can be null
    value - the value of the cell to be rendered.
    isSelected - true if the cell is to be rendered with the selection highlighted; otherwise false
    hasFocus - if true, render cell appropriately.
    row - the row index of the cell being drawn.
    column - the column index of the cell being drawn
    So to acheive your requrement, you have to do something like this.
    1 - apply the required color to first cell of the first row
    2 - configure in such a way that it works when the renderer reads first row and first column.
    For. e.g To set the background color as Blue,
         if(row == 0) && ( column == 0){
         this.setBackground(Color.Blue);                          }else {
              this.setBackground(defaultColor);
    Hope it gives a good picture.

  • Setting row color in JTable

    I am trying to display some rows in a JTable in a different color regardless of selection status. The row color criteria would be from data from the object in the row, i.e., given a certain status of a record, I would want to show it as red instead of black.

    A few optimizations:
    class StatusColorRenderer
    extends DefaultTableCellRenderer
        public StatusColorRenderer()
            // super(); not needed, call by default
            setOpaque(true);
            // DefaultTableCellRenderer returns itself as a CellRenderer Component, it extends JLabel so you can call setOpaque on it
    // since this method is called at every paint for every cell it should be HIGHLY optimized
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
        Component c = super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column);
        MyObjectClass myObject  = ( MyObjectClass ) myTableModel.getMyVector().elementAt(row);
        <SomeClass> myStatus = myObject.getTheStatus();
        if ( myStatus.compareTo(Status.BAD_STAT) == 0)
            c.setForeground(Color.red);
        else if (myStatus.compareTo(Status.IN_PROGRESS) == 0)
            c.setForeground(Color.green);
        else if ( myObject.getOtherFactor().compareTo(OtherFactors.NOT_DEFAULT) ==  0)
            c.setForeground(Color.blue);
        else
            c.setForeground(Color.black);
        // c.repaint(); NEVER DO THAT
        return c;
    StatusColorRenderer myRenderer = new StatusColorRenderer();
    // only one instance of the renderer
    for ( int i = myTableModel.getColumnCount() - 1 ; i >= 0 ; i-- )
       //column = myTable.getColumnModel().getColumn( i );
       myTable.setDefaultRenderer( myTable.getColumnClass( i ),
                                                myRenderer );
    }Comment:
    AbstractTableModel and DefaultTableModel.getColumnClass method returns Object.class, it is used by the JTable to setup the editor and the renderer of a column
    so if you're using the DefaultTableModel and JTable without overriden getColumnClass, you can set a generic renderer for your JTable by using:
    myTable.setDefaultRenderer( Object.class, myRenderer );

  • JTable:  Howto: Row color depending on value

    Hi all
    I would like to write a cell renderer that changes the background color of a row (or indivicual cells) depending on the value in one of the table columns. For example, if the value in column 'recursive' of a given row is 'true' then make the row (cell) backgroundd grey. if 'false' make white.
    I ve been able to write a simple cell renderer:
    public class colorTableCellRenderer extends DefaultTableCellRenderer
    java.awt.Color recursiveBG = new java.awt.Color(240, 240,240);
    public colorTableCellRenderer()
    super();
    public void setValue(Object value)
    String text = (String)value;
    this.setBackground(recursiveBG);
    this.setText(text);
    But i am lost on how to actually check the value of the other column so I can determine which color to choose.
    Help is greately appreciated.
    Cheers,
    michael

    Hi Laszlo
    Ok, I think this needs an explanation. Here is what I want to do:
    1. Depending on the value of column 0 compared to an external value (referenced), I want to mark a row by setting the background of the row to recursiveBG. All others should have a white background.
            if(selectedPerson.equals(sourceID)) // row is not recursive
              this.setBackground(Color.white);
            else // row IS recursive
              this.setBackground(recursiveBG);
              }This should just set the background color of the cell. If I select the row, the 'normal' behaviour should mark the row blue (or whatever is standard). Your counting is right, these states should be accomodated for.
    Current full code is below:
    public class colorTableCellRenderer extends DefaultTableCellRenderer
      java.awt.Color recursiveBG = new java.awt.Color(240, 240,240);
      int recursiveColumn = 4;
      String recursiveID = null;
      Connect connectRef = null;
      public colorTableCellRenderer(Connect connectRef)
        super();
        this.connectRef = connectRef;
      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
            java.awt.Color recursiveColor = new java.awt.Color(240,240,240);
            String myVal = (String)value;
            this.setText(myVal);
            recursiveID = (String)table.getValueAt(row, recursiveColumn);
            String selectedPerson = connectRef.getSelectedPersonPID();
            String sourceID = (String)table.getValueAt(row, 6);
            if(selectedPerson.equals(sourceID)) // row is not recursive
              this.setBackground(Color.white);
            else // row IS recursive
              this.setBackground(recursiveBG);
              return this;
    [/CODE]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • HELP!! set the cell color in jTable

    I need to set the color of a specific cell in jTable, but, I need to retain the old color in the jTable. It must not reset the whole table.
    would anyone help me in this problem... PLSSSSS its urgent

    A flexible variation on this is to specify formatting options in the JTable's client properties:
    // Use some sort of special "key" to indicate the cell and that you want to set the background color
    String key = "background:" + row + "," + column;
    table.putClientProperty(key, Color.green);You can then write a general table cell renderer that looks for these special formatting options and it doesn't disrupt your existing TableModel in any way:
    public class FormattingTableCellRenderer extends DefaultTableCellRenderer
      public Component getTableCellRendererComponent(JTable table, Object value, int row, int column, ...)
        Component component = super.getTableCellRendererComponent(table, value, row, column, ...);
        // See if the JTable specifies any properties to override the default format
        Color backgroundColor = (Color)table.getClientProperty("background:" + row + "," + column);
        if(backgroundColor != null)
          component.setBackground(backgroundColor);
        return component;
    }Any custom cell renderers you have then simply need to extend FormatTableCellRenderer instead of DefaultTableCellRenderer.
    It's very easy to add formatting options other than background, such as font, to the list of recognised attributes. You'll probably need to make some alterations to get it to recognise selection/focus but hopefully you get the idea.
    Hope this helps.

  • Changing JTable Row Color OnMouseOver

    Hello everybody,
    is it possible to change JTable Row Color when Mouse passes over it ??
    THanks!

    Yes...
    You have to override the table cell renderer and set the color of the rows based on flag.
    The flag can be turned on/off in a mouse motion listener of the table.

  • SQL Update a Single Row Multiple Times Using 2 Data Sets

    I'm working in tsql and have an issue where I need to do multiple updates to a single row based on multiple conditions. 
    By Rank_
    If the column is NULL I need it to update no matter what the Rank is.
    If the Ranks are the same I need it to update in order of T2_ID.
    And I need it to use the last updated output.
    I've tried using the update statement below but it only does the first update and the rest are ignored. Here is an example of the data sets i'm working w/ and the Desired results. Thanks in advance!
    update a
    set Middle = case when a.Rank_> b.Rank_ OR a.Middle IS NULL then ISNULL(b.Middle,a.Middle) end,
    LName = case when a.Rank_> b.Rank_ OR a.Lname IS NULL then ISNULL(b.LName,a.LName) end,
    Rank_ = case when a.Rank_> b.Rank_ then b.Rank_ end
    from #temp1 a
    inner join #temp2 b on a.fname = b.fname
    where b.T2_ID in (select top 100% T2_ID from #temp2 order by T2_ID asc)

    The Merge clause actually errors because it attempt to update the same record.  I think this CTE statement is the closest I've come but I'm still working through it as I'm not too familiar w/ them.  It returns multiple rows which I will have to
    insert into a temp table to update since the resulting row I need is the last in the table.
    ;WITH cteRowNumber
    AS(
    Select DISTINCT
    Row_Number() OVER(PARTITION BY a.LName ORDER BY a.LName ASC, a.Rank_ DESC,b.T2ID ASC) AS RowNumber
    ,a.FName
    ,a.LName
    ,b.LName as xLname
    ,a.MName
    ,b.MName AS xMName
    ,a.Rank_
    ,b.Rank_ AS xRank
    ,b.T2ID
    FROM #temp1 a
    inner join #temp2 b
    ON a.fname = b.fname
    ), cteCursor
    AS(
    Select a.RowNumber,
    a.Fname
    ,a.LName
    ,a.xLname
    ,a.MName
    ,a.xMName
    ,a.xRank
    ,a.T2ID
    ,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xRank,a.Rank_) else ISNULL(a.Rank_,a.xRank) end AS Alt_Rank_
    ,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xMName,a.MName) else ISNULL(a.MName,a.xMName) end AS Alt_MName
    ,CASE WHEN a.Rank_ >= a.xRank THEN ISNULL(a.xLName,a.lname) else ISNULL(a.LName,a.xlname) end as Alt_Lname
    FROM cteRowNumber a
    where a.RowNumber = 1
    UNION ALL
    Select crt.RowNumber
    ,crt.FName
    ,crt.LName
    ,crt.xLname
    ,crt.MName
    ,crt.xMName
    ,crt.xRank
    ,crt.T2ID
    ,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xRank,Prev.Alt_Rank_) else ISNULL(Prev.Alt_Rank_,crt.xRank) end AS Alt_Rank
    ,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xMName,Prev.Alt_MName) else ISNULL(Prev.Alt_MName,crt.xMName) end AS Alt_MName
    ,CASE WHEN Prev.Alt_Rank_ >= crt.xRank THEN ISNULL(crt.xLName,Prev.Alt_Lname) else ISNULL(Prev.Alt_Lname,crt.xLName) end as Alt_Lname
    FROM cteCursor prev
    inner join cteRowNumber crt
    on prev.fname = crt.fname and prev.RowNumber + 1 = crt.RowNumber
    SELECT cte.*
    FROM cteCursor cte

  • How can i set the alternating colors for a table rows

    Dear All,
    Please any one help me how can i set the Alternating colors for Table Rows.
    i created a theam there i set the background alternating color to brown and i set the table design properity to alternating. but it is not reflecting.

    Hi,
    The design property in Table properties should work for your requirement. Select "alternating" value for design.
    Please see the API below:
    design
    Determines the appearance of the table. The property design can take the following values and is represented by enumeration type WDTableDesign.
    alternating - The table rows are displayed alternately in a different color.
    standard - The table background has one color. The individual table rows are displayed with grid net lines.
    transparent - The table background is transparent. The individual table rows are displayed without grid net lines.
    Check whether you have changed the right property or not? Also table should contain more than one rows to test this scenario.
    Regards,
    Jaya.
    Edited by: VJR on Jun 17, 2009 6:43 PM

  • How to change the background color of a single row

    Hi OTN,
    I am using JDeveloper 11.1.1.2 with ADF faces in view layer.My issue is How to change the background color of a single row in af:table ?.

    How to highlight ADF table row based on column value?
    Found by searching

Maybe you are looking for