Problem when setting JTable cell color.

hello,
when I setting color for particular table cell, it sets.
but, when I click another row (another cell) , the color of the previous cell disabled and it visible only when I click that cells row.
how can I permanatly set the color for the rows depends on input data.
for example,
if a device is connected, I want to give the cell color GREEN.
if device is not connected , i want to give the color as RED.
thank you.

but, when I click another row (another cell) , the color of the previous cell disabled and it visible only when I click that cells row.It appears you applied color to cell editor.
tableObj.getComponentAt(x,y).setForeground(Color.red);
tableObj.getComponentAt(x,y).setBackground(Color.red); or could be solved properl if you post the code

Similar Messages

  • Setting jtables cell color

    Hi,
    I would like to know if anyone know how to set a specific cell colour in a JTable, or if they know any links to when i can find help...thanks in advance
    Rudy

    Take a look at TableCellRenderer and its default implementation
    HTH
    Mike

  • Setting JTable cell editor

    Hallo,
    I have troubles setting jtable cell edtior. when i run code below, editor stays unchnaged.
    Do you know where's the problem, please (except in programmer^_^) ???
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    public class Test extends JFrame {
        JTable table;
        Test() {
            // Create table model
            table = new JTable();
            table.setModel(new DefaultTableModel(
                new Object[][] {
                    { Boolean.TRUE, Integer.valueOf(10) },
                    { "Hallo!", Boolean.FALSE },
                }, new String[] { "Col1", "Col2" }));
            // Setup frame a little
            setLayout(new BorderLayout());
            setBounds(new Rectangle(300,300,200,100));
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            add(table,BorderLayout.CENTER);
             * Two calls below have no effect:-(
             * What did i wrong?
            // set cell editor for all cells
            table.setCellEditor(new DefaultCellEditor(
                    new JComboBox(new String[] { "0", "1" }) ));
            // Use checkbox for booleans
            table.setDefaultEditor(Boolean.class, new DefaultCellEditor(
                    new JCheckBox() ));
            // Use combobox for strings
            table.setDefaultEditor(String.class, new DefaultCellEditor(
                    new JComboBox( new String[] { "Hallo!", "Bye!" } ) ));
        public static void main(String[] arg) {
            Test test = new Test();
            test.setVisible(true);
    }

    Hi again,
    yes it works when i set it for single column, but i'd like to use default editor, because column count is not fixed.
    According to documentation: "Sets a default cell editor to be used if no editor has been set in a TableColumn. If no editing is required in a table, or a particular column in a table, uses the isCellEditable method in the TableModel interface to ensure that this JTable will not start an editor in these columns. If editor is null, removes the default editor for this column class."
    So when i call
    column.setCellEditor(null); in TableColumnModelListener columnAdded event. But still it's not working. See sample below (i've changed it to cell renderer coz result is clear on single view, but problem stays same)
    More over problem seems to be with algoritm that decide which class to use. Object takes preference any time. W/o it npe arries.
    Regards
    Adam
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.DefaultTableModel;
    public class Test extends JFrame {
        JTable table;
        Test() {
            // Create table model
            table = new JTable();
            table.setModel(new DefaultTableModel(
                new Object[][] {
                    { Boolean.TRUE, Integer.valueOf(10) },
                    { "Hallo!", Boolean.FALSE },
                }, new String[] { "Col1", "Col2" }));
            // Setup frame a little
            setLayout(new BorderLayout());
            setBounds(new Rectangle(300,300,200,100));
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            add(table,BorderLayout.CENTER);
            table.setDefaultRenderer(Object.class,new Renderer(Color.YELLOW));
            table.setDefaultRenderer(String.class,new Renderer(Color.BLUE));
            table.setDefaultRenderer(Boolean.class,new Renderer(Color.RED));
            table.setDefaultRenderer(Integer.class,new Renderer(Color.GREEN));
            // use default renderer in all columns
            table.getColumn(table.getColumnName(0)).setCellRenderer(null);
            table.getColumn(table.getColumnName(0)).setCellRenderer(null);       
        public static void main(String[] arg) {
            Test test = new Test();
            test.setVisible(true);
        class Renderer extends DefaultTableCellRenderer {
            Color color;
            Renderer(Color color) { this.color = color; }
            public Component getTableCellRendererComponent(JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                setBackground(color);
                setToolTipText("Class is "+value.getClass().getName());
                return this;
    }Message was edited by:
    a3cchan

  • 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.

  • How to set JTable cell editable/non-editable dynamically using NetBean?

    I am using NetBean 6.5, create a database desktop application, I using the persistence entity manager to bind my JTable with database.
    Now, I want to set practicular cells which are enable and disable, I tried to create my own table model and override the isEditable() method, which it seems didn't work. I guessed the problem is the persistence connection between my Table and database.
    How can I solve it? Any example? I just googled the web and can't find example which use netbean combined with database. I know that a single JTable would work when creating your own model.
    thx.

    I know what coding i did, Yes u r right but im new to GUI programming only,
    That's why i posted it to forums, I gone through the Control Flow Statements link what u have given.
    U didnt get my question at all.
    Again the problem im facing is the table is already displayed with 2nd column uneditable.
    When some Action done on table, i need to make 2nd column editable at run time.
    Thanks if u provide me the solution instead of deciding what type of programmer im.

  • How to set JTable cells to uneditable

    I was trying to set the cells in my Jtable to uneditable.
    I overrided the isCellEditable method. Here is what I did. But the
    cells remain editable. Any ideas?
    private class MyTableModel extends DefaultTableModel
    public MyTableModel(Vector vectRow,Vector vecColumn)
    super(vecVector,vecColumn);
    public boolean isCellEditable(int row, int col)
    if (col >= 0) {
    return false;
    }

    Just Use:
    public boolean isCellEditable(int r, int c) { return false; }

  • Code to change JTable cell color not working

    My code below is supposed to change the color
    of a single JTable cell however its not working.
    Could anyone please tell me why?
    Here's the code:
    import java.awt.*;
    import javax.swing.table.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class ColorTable extends JTable {
    public ColorTable() {
    AbstractTableModel tableModel = new AbstractTableModel() {
    public Class getColumnClass(int column) { return Integer.class; }
    public int getColumnCount() { return 6; }
    public int getRowCount() { return 10;}
    public Object getValueAt(int row,int col) { return new Integer(row * col); }
    setModel(tableModel);
    setDefaultRenderer(Integer.class,new ColorRenderer(Color.cyan));
    this.setRowSelectionAllowed(false);
    this.setCellSelectionEnabled(true);
    addMouseListener(new MouseAdapter() {
    private ColorRenderer renderer;
    private JColorChooser chooser = new JColorChooser();
    public void mousePressed(MouseEvent e) {
    if(e.getModifiers() == MouseEvent.BUTTON3_MASK) {
    System.out.print("rowAtPoint(e.getPoint())=" +rowAtPoint(e.getPoint()));
    System.out.print( "columnAtPoint(e.getPoint()))=" + columnAtPoint(e.getPoint()));
    renderer = (ColorRenderer)getCellRenderer(rowAtPoint(e.getPoint()), columnAtPoint(e.getPoint()));
    // chooser.setColor(renderer.getColor());
    renderer.setColor(chooser.showDialog((Component)e.getSource(),"Choose Cell Color",chooser.getColor()));
    class ColorRenderer extends DefaultTableCellRenderer {
    private Color cellColor;
    public ColorRenderer(Color color) { cellColor = color; }
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    System.out.print("row= " + row + "\n");
    System.out.print("column= " + column + "\n");
    System.out.print("OBJECT VALUE=" + value.toString());
    //Component comp = super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
    super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
    if (isSelected) {
    setOpaque(true);
    setBackground(cellColor);
    else {
    setBackground(Color.white);
    setForeground(Color.black);
    return this;
    public void setColor(Color color)
    cellColor = color;
    ColorTable.this.repaint();
    public Color getColor() { return cellColor; }
    public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    ColorTable table = new ColorTable();
    panel.add(table);
    frame.getContentPane().add(panel);
    frame.setSize(500,250);
    frame.setVisible(true);

    My code below is supposed to change the color
    of a single JTable cell however its not working.
    Could anyone please tell me why?
    Here's the code:
    import java.awt.*;
    import javax.swing.table.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class ColorTable extends JTable {
    public ColorTable() {
    AbstractTableModel tableModel = new AbstractTableModel() {
    public Class getColumnClass(int column) { return Integer.class; }
    public int getColumnCount() { return 6; }
    public int getRowCount() { return 10;}
    public Object getValueAt(int row,int col) { return new Integer(row * col); }
    setModel(tableModel);
    setDefaultRenderer(Integer.class,new ColorRenderer(Color.cyan));
    this.setRowSelectionAllowed(false);
    this.setCellSelectionEnabled(true);
    addMouseListener(new MouseAdapter() {
    private ColorRenderer renderer;
    private JColorChooser chooser = new JColorChooser();
    public void mousePressed(MouseEvent e) {
    if(e.getModifiers() == MouseEvent.BUTTON3_MASK) {
    System.out.print("rowAtPoint(e.getPoint())=" +rowAtPoint(e.getPoint()));
    System.out.print( "columnAtPoint(e.getPoint()))=" + columnAtPoint(e.getPoint()));
    renderer = (ColorRenderer)getCellRenderer(rowAtPoint(e.getPoint()), columnAtPoint(e.getPoint()));
    // chooser.setColor(renderer.getColor());
    renderer.setColor(chooser.showDialog((Component)e.getSource(),"Choose Cell Color",chooser.getColor()));
    class ColorRenderer extends DefaultTableCellRenderer {
    private Color cellColor;
    public ColorRenderer(Color color) { cellColor = color; }
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    System.out.print("row= " + row + "\n");
    System.out.print("column= " + column + "\n");
    System.out.print("OBJECT VALUE=" + value.toString());
    //Component comp = super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
    super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column);
    if (isSelected) {
    setOpaque(true);
    setBackground(cellColor);
    else {
    setBackground(Color.white);
    setForeground(Color.black);
    return this;
    public void setColor(Color color)
    cellColor = color;
    ColorTable.this.repaint();
    public Color getColor() { return cellColor; }
    public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    ColorTable table = new ColorTable();
    panel.add(table);
    frame.getContentPane().add(panel);
    frame.setSize(500,250);
    frame.setVisible(true);

  • Problem in setting the background color of jtable with Nimbus

    Hi
    I have created a java swing application. In which I am using JTable.
    When creating a simple JTable and displaying with Nimbus, the row background color alternates between white and a light blue-grey.
    I want the table with single colour. Only the first column should be grey colour and other should be white.
    I used this code to set the background and foreground colour.
    public Component prepareRenderer
        (TableCellRenderer renderer, int index_row, int index_col){      
                Component objComponent = super.prepareRenderer(renderer, index_row, index_col);         
                Color objGreyColour = new Color(240,240,240);
                Color objWhiteColour = new Color(255,255,255);
                if(index_col == 0){
                    objComponent.setBackground(objGreyColour);
                    objComponent.setFont(new java.awt.Font(CommonClass.getFontName(),java.awt.Font.BOLD, CommonClass.getFontSize()));
                    objComponent.setForeground(Color.BLACK);
                }else{               
                    setSelectionBackground(Color.BLUE);
                    objComponent.setBackground(objWhiteColour);
                    objComponent.setForeground(Color.BLACK);
                return objComponent;
            } Look wise it is fine but when i try to select the cell it is not highlighting the cell and also i m not able to select multiple cell with ctrl key.
    Any help would be appreciated
    Thanks
    Sonal

    Hello,
    1) if you want better help soone,r please post an SSCCE (http://sscce.org) instead of a code extract.
    2) selection highlighting is lost because your code... doesn't handle selection. To take selection into account, you can use <tt>if (super.isRowselected(index_row)) {...}</TT>.
    Regards,
    J.

  • JTable ..... set background cell color?

    Hi!
    I've read the many examples on here of doing such .... but still dont see how to call the renderer in to do this.
    My app calculates several variables, then posts the answer to my jTable10 answer column(11) .... row after row.
    Now , I want to add this:
    For each answer, I will test to see if (outVal) answer is <4 or >12,
    If true for this test, I need to post the answer and also change the background of that cell to RED color.
    I dont know how to construct the renderer to do this.
    Thanks!

    This is the code that does the calculations for the jTable10 ... and make a call to the render:
    import java.awt.Component;
    import java.text.DecimalFormat;
    import java.util.ArrayList;
    import javax.swing.JTable;
    import javax.swing.RowFilter;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableModel;
    import javax.swing.table.TableRowSorter;
    * @author Richard
    public class MathTapCal {
         public static ArrayList<Double> alist1 = new ArrayList<Double>(100);
        /** Creates a new instance of MathTapCal */
                public MathTapCal() {
            String group;
                    DecimalFormat df= new DecimalFormat("#0.00");
                    int rc;
                    int ampVal;
                    int sor = 0;
                    int tVal = 0;
                    int z = 0;
                    int rowLen;
                    int startVal_A;
                    int arrayVal;
                    int aVal;
                    int split = 0;
                    double tapLoss = 0;
                    double calTapValue;
                    double lenVal;
                    double cabLossVal = 0;
                    double tapVal = 0;
                    double sigOutVal = 0;
                    double calEndVal;
                    double designVal;
                    Object stVal;
                    Object bb;
                    Object valx;
                    Object calTapVal_s;
                    String valxx;
                    String text;
                    String cabLossVal_s;
                    String startVal_x;
                    String rcc;
                    String stVal1;
                    String cc;
                    String splitx;
                    String av;
                    String dd;
                    Double startVal;
                    Double totalLoss;
                    bb = (String)CATV_Cal.jComboBox1.getSelectedItem();// amp db output
                    ampVal = Integer.parseInt((String) bb);
                    startVal_A = ampVal - 12;
                    startVal_x = df.format(startVal_A);
                    startVal = new Double(startVal_A);
                    av = CATV_Cal.jButton6.getText();// row lenght
                    rowLen = Integer.parseInt((String) av);
                    splitx = (String)CATV_Cal.jComboBox2.getSelectedItem();// splitter port size
                    arrayVal = Integer.parseInt((String) splitx);
                    alist1.clear();
               for ( aVal=0; aVal<arrayVal; aVal++ ) {
                    alist1.add(startVal); //load the Array with start vals
                    //CATV_Cal.jTable1.setValueAt(startVal_x ,tVal ,7 );
                    System.out.println("Load startVal>>>>>>>>>>>  !!!!!!!!!!!!!!!"+startVal); 
                    rcc = CATV_Cal.jButton6.getText();// length of table
                    rc = Integer.parseInt(rcc);
                for ( ; ; ){
                    //group = (String)CATV_Cal.jComboBox3.getSelectedItem();  
                    sor = sor +1;// sort table call split leg 1, 2, 3, etc.    
                    text = Integer.toString(sor);
                    TableModel model =  CATV_Cal.jTable10.getModel();
                    JTable table = new JTable(model);
                    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
                    CATV_Cal.jTable10.setRowSorter(sorter);
                    sorter.setRowFilter(null);
                    //sorter.setRowFilter(RowFilter.regexFilter("^"+group+"$",1));
                    sorter.setRowFilter(RowFilter.regexFilter("^"+text+"$",3));
                    sorter.toggleSortOrder(2);//cable length
                    System.out.println("SOR  !!!!!!!!!!!!!!!"+sor);
                    dd = (String)CATV_Cal.jComboBox2.getSelectedItem();// splitter port size
                    split = Integer.parseInt((String) dd);
                    System.out.println("Splitter Port size>>>>>>>  !!!!!!!!!!!!!!!"+split); 
                for  ( tVal=0; tVal<split; tVal++ ) {
                    System.out.println("Loop tVal  !!!!!!!!!!!!!!!"+tVal);           
                if (z == rc){ // when we reach the end of the rows .... STOP !!
                    System.out.println("QUIT at Row !!!!!!!!!!!!!"+z); 
                return;
                    valx = CATV_Cal.jTable10.getValueAt(tVal,4);// cable length
                    valxx = (valx).toString();
                    lenVal = Integer.parseInt(valxx);
                    cabLossVal = lenVal * .06;//takes the cable lenght and times it by the loss per foot factor
                    cabLossVal_s = df.format(cabLossVal);
                    CATV_Cal.jTable10.setValueAt(cabLossVal_s ,tVal ,5 );
                    System.out.println("Cable Loss >>>>>>> !!!!!!!!!!!!!!!"+cabLossVal); 
                   // CATV_Cal.jTable1.setValueAt(tVal , ,6 ); // test !!.............!!!!only 
                    stVal = alist1.get(tVal);  // get startValue item from Array
                     stVal1 = (stVal).toString();
                    startVal = Double.parseDouble(stVal1);
                    String startVal_s = df.format(startVal);
                    CATV_Cal.jTable10.setValueAt(startVal_s ,tVal ,7 );// sets the start SignalValue box
                    //System.out.println("TVal !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"+tVal);
                    cc = (String)CATV_Cal.jComboBox4.getSelectedItem();// END Design Value
                    designVal = Double.parseDouble(cc);
                    totalLoss = cabLossVal + designVal; // design value = cc
                    System.out.println("totalLoss>>>>>>>>>>  !!!!!!!!!!!!!!!"+totalLoss); 
                    calTapValue = startVal - totalLoss;
                    calTapVal_s = df.format(calTapValue);
                    CATV_Cal.jTable10.setValueAt(calTapVal_s ,tVal ,9 );
                    System.out.println("calTapVal ="+calTapVal_s); 
                    if (calTapValue  <= 5 ){
                        tapVal = 4;
                        tapLoss = 4;
                    if (calTapValue  >= 5 && calTapValue <=7.5){
                        tapVal = 6;
                        tapLoss = 3.5;
                    if (calTapValue  >= 7.5 && calTapValue <=10.5){
                        tapVal = 9;
                        tapLoss = 1.6;
                    if (calTapValue  >= 10.5 && calTapValue <=14){
                        tapVal = 12;
                        tapLoss = 1.5;
                    if (calTapValue  >= 14 && calTapValue <=18){
                        tapVal = 16;
                        tapLoss = 0.7;
                    if (calTapValue  >= 18 && calTapValue <=22){
                        tapVal = 20;
                        tapLoss = 0.7;
                    if (calTapValue  >= 22 && calTapValue <=25.5){
                        tapVal = 24;
                        tapLoss = 0.6;
                    if (calTapValue  >= 25.5 && calTapValue <=28.5){
                        tapVal = 27;
                        tapLoss = 0.6;
                    if (calTapValue  >= 28.5 ){tapVal = 30;tapLoss = 0.6;}
                    CATV_Cal.jTable10.setValueAt(tapVal ,tVal ,8 );// sets the chosen standard "TAP VALUE" 4,6,9,12,16,20,24,27 or 30
                    sigOutVal = startVal - tapLoss;
                    Double sigOutVal_1 = new Double(sigOutVal);
                    alist1.set(tVal,sigOutVal_1);// sets the sigOutVal into the Array replacing the startSigVal there
                    String sigOutVal_s = df.format(sigOutVal);
                    CATV_Cal.jTable10.setValueAt(sigOutVal_s ,tVal ,11 );
                    System.out.println("sigOut ="+sigOutVal_s);
                    calEndVal = calTapValue - 8;// available db for TV
                    String calEndVal_s = df.format(calEndVal);
                    CATV_Cal.jTable10.setValueAt(calEndVal_s ,tVal ,10 );
                    System.out.println("calEndVal ="+calEndVal_s); 
                    z = z +1;  // row count incrementer
                    new CustomTableCellRenderer();// here is my call to the Renderer
    }

  • JTable cell color

    I use the following custom DefaultTableCellRenderer:
    ------------------------CustomTableCellRenderer-------------------
    import java.awt.Component;
    import java.awt.Color;
    import java.awt.Font;
    import javax.swing.JTable;
    import javax.swing.table.DefaultTableCellRenderer;
    public class CustomTableCellRenderer extends DefaultTableCellRenderer
         public Component getTableCellRendererComponent( JTable jTable, Object value,boolean isSelected, boolean hasFocus, int row,int col)
         super.getTableCellRendererComponent(jTable, value, false,
         true, row, col);
         setHorizontalAlignment(CENTER);
         if(row!=0 && !(jTable.getValueAt(row-1,col).toString().equals(value.toString()))) {
              setBackground(new Color(255,220,220));
         return this;
    -----------------main class-----------------------------------------------
    TableCellRenderer cell = new CustomTableCellRenderer();
         table.setDefaultRenderer( Object.class, cell );
    The above scheme works fine where I want to color a cell every time a change/transition occurs among the values in a particular column for each column in the table.
    The problem is, in the resulting table, all the cells appear selected and I am unable to select a set of rows or columns by clicking/dragging and trying to create a rectangular rubberband.
    Why is it not allowing me to treat this as a regular JTable instance where upon clicking any cell, the whole row gets selected?
    I suspect the 3rd and 4th arguments in the following statement, I tried all boolean combinations for it, but in vain:
    super.getTableCellRendererComponent(jTable, value, false,
         true, row, col);
    any help?

    You need to override the prepareRenderer method of the TableRenderer with something like this:
            table = new JTable(myTableModel) {
                public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int colIndex) {
                    Component c = super.prepareRenderer(renderer, rowIndex, colIndex);
                    // Set color lightyellow, lightred (inverted ones) or just like the rest of the cells.
                    String cellContent = myTableModel.getValueAt(rowIndex, 4).toString();
                    if (table.isCellSelected(rowIndex, colIndex)) {
                        // nothing to do or maybe setSelectionBackground or further if/else if/else for selected cells.
                    } else if (colIndex == 4 && cellContent.equals("content1")) {
                        c.setBackground(new Color(255, 220, 200));
                    } else if (colIndex == 4 && cellContent.contains("content2")) {
                        c.setBackground(new Color(255, 255, 220));
                    } else {
                        c.setBackground(table.getBackground());
                    return c;
            };If you don't know that c is a TableCellRenderer component you'll need instanceof check.

  • Problem dynamically setting row background color in a report

    Hi guys,
    I want a PPR Classic SQL Report to dynamically show a background color depending on what value is stored in the column of the record.
    To illustrate what I've tried consider the following:
    1. I created a PPR Report on DEPT (this is the report I want to use with record backgrounds)
    2. I created a PPR javascript call that I trigger somewhere in the page
    function refreshReport(pField, pValue){
      var region = $v('P2_DEPT_RID');
      var link ='f?p=' + $v('pFlowId') + ':' + $v('pFlowStepId') + ':' + $v('pInstance') +'::::' + pField +':'+ pValue;
      html_PPR_Report_Page(this, region, link);
    The updating of the report works fine by the way.
    3. I changed the code in the HTML Expression of the column definition of "DNAME" of the DEPT report. I used jQuery to set the class of the <tr> element of the position the field is in.
    This is the value I want to dynamically check on
    <div id="dept_#DEPTNO#">#DNAME#</div>
    <SCRIPT type=text/javascript>
    $('#dept_#DEPTNO#').parent().parent().children().removeClass('t20data');
    if ('#DNAME#' == 'RESEARCH'){
          $(function(){    
            $('#dept_#DEPTNO#').parent().parent().addClass('voorhaal_kan');
    }else{
             $(function(){    
                $('#dept_#DEPTNO#').parent().parent().addClass('sscc_ok');
    </SCRIPT>4. I created some CSS like so:
    tr.voorhaal_kan{border:1px solid #AAA;border-left:none;border-top:none;background-color:#FFDD44;padding:2px 8px;}
    tr.sscc_ok {border:1px solid #AAA;border-left:none;border-top:none;background-color:#CCFFCC;padding:2px 8px;}
    tr.sscc_manco {border:1px solid #AAA;border-left:none;border-top:none;background-color:#FF3300;padding:2px 8px;}
    tr.sscc_geel {border:1px solid #AAA;border-left:none;border-top:none;background-color:#FFFF66;padding:2px 8px;}Now the problem is, the first time I load the page, the javascript in the HTML Expression works fine! It checks the value, and colors the <tr> beautifully. But, when i Refresh the report using PPR (calling the javascript function), the report is reloaded just fine, but the javascript bit in the HTML Expression is skipped for some reason resulting with a regular background color found in "t20Standard td.t20Data" . Alerts won't fire either in the code, hence the assumption of the code skipping.
    Any ideas on how this problem can be solved?

    Hey Rutger,
    I know you've already done a lot of work in another direction, but would it be possible for your purposes to use the SQL to do what you need. check out this link:
    How to perform a conditional column format based on column value
    and Conditional coloring of Database Column
    I hope those may help or give you other ideas.
    -Marc

  • JTable cell color overriding Boolean values displayed as checkboxes. Fix?

    I have a JTable column of Boolean values that automatically appear as checkboxes. When I apply my DefaultTableCellRenderer to this column, the checkbox disappears and a "false" or "true" appears instead. But if I mouseclick on the cell, the checkbox will appear momentarily.
    Any suggestions for getting the Boolean value displayed as a checkbox and seeing my colors change? (I suppose the easy way is using JCheckBox, but I'm curious if I can do it using Boolean)
    Thanks for the help. Code follows for the cell renderer.
    class ColorRenderer extends DefaultTableCellRenderer{
    public ColorRenderer() {
    super();
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (isSelected == true) {
      setBackground(Color.getHSBColor(100, 100, 1));
      setForeground(Color.BLACK);
    } else {
      setBackground(Color.LIGHT_GRAY);
      setForeground(Color.WHITE);
    if (hasFocus == true) {
      setBackground(Color.RED);
      setForeground(Color.WHITE);
    setOpaque(true);
    setValue(value);
    return this;

    Wouldn't extend DefaultTableCellRenderer as that extends a JLabel
    I would extend a JCheckBox and implement TableCellRenderer.

  • Problem when setting encoding to ISO-8859-1

    Hi. Is there something I'm missing when it comes to setting
    encoding? Here are the code in the mxml:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute">
    </Application>
    In the html-template I'm setting:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=ISO-8859-1" />
    The code for sending data from the app:
    <mx:HTTPService
    id="service"
    url="encoding.jsp"
    method="post"
    showBusyCursor="true"
    result="onResult(event)"
    resultFormat="xml"
    contentType="application/xml"
    fault="onFault(event)"
    useProxy="false" />
    public function send():void {
    var xml:XML = <Data>{data.text}</Data>;
    service.send(xml);
    But still the respons jsp I have made says it receives the
    data in UTF-8 format? What am I doing wrong?
    Servercode:
    don't work: BufferedReader reader = new BufferedReader( new
    InputStreamReader( is ) );
    work: BufferedReader reader = new BufferedReader( new
    InputStreamReader( is, "UTF-8") );

    Are there no-one who have the same problem? I've tried
    everything imaginable, and still the serverside receives the data
    as UTF-8.
    Is it supported at all to set the encoding of the
    request?

  • Problems when setting SSL for a MQSeries Adapter

    I'm trying to enable SSL and so far these are the steps I've done:
    - I've been using the DemoIdentity.jks and DemoTrust.jks files located under <MIDDLEWARE_HOME>\wlserver_10.3\server\lib for all my certificate operations.
    - I created a PrivateKey and imported it to my DemoIdentity store, created a certificate request and when I got the response imported it back using the same alias. Something I want to highlight here is that when I created the PrivateKey I left the password field empty so it supposed inherit the keystore's.
    - I also imported the CA cert into the DemoTrust.jks
    My MQAdapter is all set and when I used it with no SSL it was working just fine so I think I have the problem isolated.
    Anyway, now when I try to connect this is what I'm getting in the logs:
    at oracle.integration.platform.blocks.adapter.fw.jca.cci.JCAConnectionMa
    nager$JCAConnectionPool.createJCAConnection(JCAConnectionManager.java:1335)
    ... 59 more
    Caused by: java.security.UnrecoverableKeyException: Cannot recover key at sun.security.provider.KeyProtector.recover(KeyProtector.java:311)
    at sun.security.provider.JavaKeyStore.engineGetKey(JavaKeyStore.java:121
    at sun.security.provider.JavaKeyStore$JKS.engineGetKey(JavaKeyStore.java
    :38)
    at java.security.KeyStore.getKey(KeyStore.java:763)
    at com.sun.net.ssl.internal.ssl.SunX509KeyManagerImpl.<init>(SunX509KeyM
    anagerImpl.java:113)
    at com.sun.net.ssl.internal.ssl.KeyManagerFactoryImpl$SunX509.engineInit
    (KeyManagerFactoryImpl.java:48)
    at javax.net.ssl.KeyManagerFactory.init(KeyManagerFactory.java:239)
    at oracle.tip.adapter.mq.ManagedConnectionImpl.setupSSLSocketFactory(Man
    agedConnectionImpl.java:670)
    Googling this it seems like it's a problem with the keystore and private key passwords being different but I changed the private key's to match the keystore (something that I shouldn't be necessary because of the keytool's default behavior when generating the key) with no positive results.
    Anyway, any ideas would be really appreciated. I've been spinning my wheels on this issue for 3 days now.
    BTW, here's I'm using Oracle SOA11g.

    Hello MV,
    I don't need to access my console through SSL as this is not part of what I'm trying to do.This will confirm whether SSL has been enabled on your weblogic. In your case it seems that SSL has not been enabled.
    the demo keystore and truststore are regular stores and I was able to successfully import certificates into them using keytool.Demo keystores are not recommended to be used in production. Moreover DemoIdentity.jks already has a private (secret) key so importing another key may cause an issue. I don't think any application server supports multiple private keys for SSL.
    I'll go ahead anyway and create a brand new set of keystores just to rule out that's not the problem here.Please test with new custom keystores and let us know the results.
    Regards,
    Anuj

  • Problem when setting cursor position property

    I'm trying to use property nodes to set the cursor position programmatically, following an arrow keypress.  When my actual data file plotted, the position assignment doesn't work properly.  If I clear the data from the graph (right click, clear graph), then the cursor responds properly.  I've attached a zipped file with VI that demonstrates the problem.  Sorry the file is large--I had to include my data file to properly demonstrate the problem.
    Thanks for any advice that help me clear this up,
    Allan
    Solved!
    Go to Solution.
    Attachments:
    My Source Distribution.zip ‏541 KB

    bracker wrote:
    I'm trying to use property nodes to set the cursor position programmatically, following an arrow keypress.  When my actual data file plotted, the position assignment doesn't work properly.  If I clear the data from the graph (right click, clear graph), then the cursor responds properly.  I've attached a zipped file with VI that demonstrates the problem.  Sorry the file is large--I had to include my data file to properly demonstrate the problem.
    Thanks for any advice that help me clear this up,
    Allan
    Include this code in 'Initialize' state.
    I am not allergic to Kudos, in fact I love Kudos.
     Make your LabVIEW experience more CONVENIENT.

Maybe you are looking for

  • TS1538 iPhone 2G not recognized by iTunes after erasing all content

    Okay, I am trying to fix and iPhone 2G. I decided to erase its contents, which apparently erased the iOS as well. However, how can I add an iOS if iTunes and my computer are not recognizing it? I already have the 3.12 IPSW downloaded so I could have

  • Command line wasn't executed in ftp adapter

    Hi,gurus:     I met a problem when I used "Run operating system command before message processing" in a file to file scenario.After the message was processed successfully I found the command wasn't executed.However,the command(bat file) could be exec

  • G/l upload

    how  can upload the initial balance in to particular a/c? plz give me t-code( non sap to sap)

  • 100% width and 100% height slideshow in Muse

    Hi, In Muse is it possible have a  slideshow that maintains full 100% width image but increases the slideshow height as the browser width is increased? In other words, I would like the slide show image to be say 1000px x 500px but if the viewer pulls

  • Lenovo G510, the Intel HD Graphics 4600 and Radeon 8750M, will not work!

    Good evening, I have a Lenovo G510, 59401564, i7 with Intel HD Graphics 4600 and Radeon 8750M graphics card. I have problems with graphics cards to get it to work permanently! The installation of the graphics card driver works fine but after about 30