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.

Similar Messages

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

  • Can I invoke a SubVI in an event? and how do I set the background color of a pipe to #0000ff?

    When I click an image or a glass pipe(which belongs to Industry/Chesmitry category in palette), I want a SubVI to be invoked.
    The purpose is to fetch an OPC-UA data from a web service and to write to it via the service.
    We are building an HMI solution which displays an interactive water plant diagram.
    When users click pipes and motors in the diagram, clicked devices should be turned on and off and change their animations or colors accordingly.
    OPC-UA is for communication with devices.
    I couldn't even set the background color of a pipe to "#0000ff", but setting it to "Red" or "Blue" was possible, and I don't know how to invoke SubVIs in event scripts.
    The documentations in NI.com are confusing and lack depth.
    Even silverlight references are confusing.
    How do I do all of these?

    Hi iCat,
    Can you provide some more information about your current implementation so that we can help to answer your questions. Some questions I have for you are:
    Are you creating this project in the NI LabVIEW Web UI Builder or in LabVIEW?
    How are you publishing your webservice? Is this also in LabVIEW?
    How is your webservice interacting with an OPC-UA server?
    How is the certification set up with OPC-UA so that you can communicate between the server and the client?
    Best Regards,
    Allison M.
    Applications Engineer
    National Instruments
    ni.com/support

  • How to set the Background Color of a Text Field in a Tabular Report.

    Hello,
    I tried to set the Background Color of a Text Field in a Tabular Report.
    But I was not able to change this colur.
    In the report attributes --> column attributes
    I tried already:
    1. Column Formating -- >CSS Style (bgcolor: red)
    2. Tabular Form Element --> Element Attributes (bgcolor: red)
    but nothing worked.
    Can anybody help me?
    I Use Oracle Apex 2.2.1 on 10gR2
    thank you in advance.
    Oliver

    in "Report Attributes" select the column to move to the "Column Attributes" page. In the "Element Attributes" field under the "Tabular Form Element" region enter
    style="background-color:red;"
    I will also check if there is a way to do this via the template and post here again
    edit:
    in your template definition, above the template, enter the following:
    < STYLE TYPE="text/css" >
    .class INPUT {background-color:red;}
    < /STYLE >
    (remove the spaces after the < and before the >)
    change "class" to the class that the template is calling
    (I'm using theme 9, the table has: class="t9GCCReportsStyle1" so I would enter t9GCCReportsStyle1)
    A side-effect of using this second version is that ALL input types will have a red background color--checkboxes, input boxes, etc.
    Message was edited by:
    TheJosh

  • How do I set the background color of a page_item?

    I've been pasting "background-color:#5CD65C" in a number of places, like "HTML Table Cell Attributes" under the Label and the Element tabs, but get no results. Can anyone tell me how to set the background color of a cell, please?

    Hi Doug,
    Dynamic Actions is an alternative also, especially if it is conditional.
    Action Set Style
    Fire When Event Result Is True
    Style Name background-color
    Value #5CD65C
    Selection Type DOM Object
    DOM Object your item name
    Set your Condition Type and you have it.
    Jeff
    Edited by: jwellsnh on May 24, 2011 3:55 PM

  • How can I set the background color of JLabel?

    Can any one tell me how to set the background color of a JLabel?
    I have:
    JLabel prop = new JLabel("blahblah");
    prop.setBackground(Color.red);
    Thank you in advance...

    JLabel prop = new JLabel("blahblah");
    prop.setBackground(Color.red);
    prop.setOpaque(true);

  • How 2 set the background color in j2me

    Can any body tell me how to set the background color to midlet.??

    if you are using Screen then you can call its setBackColor()
    or if you are using Canvas then you can call
    g.setColor(r,g,b);
    g.fillRect(0,0,getWidth,getHieght);
    where g is the Graphics instance of Canvas,for further information consult documentation

  • Why does the eyedropper tool set the background color swatch instead of the foreground?

    Whenever I try to use the eyedropper tool in Photoshop CS5, the eyedroper sets the background color instead of the foreground. I know you can swap the colors with the arrows, but Photoshop used to be able to just put the color in the foreground swatch without me doing any extra manual work. How do I restore it?

    Click on Windows and color.  There is a setting there to change from
    foreground to background.  The one with the box around it is the default setting.

  • Writing own TableCellRenderer for setting the Background Color of a cell ?

    Hello,
    I am using the JTable and DefaultTableModel for my GUI. I use also only plain text in the rows and columns. I have a method which examine every row wether something is wrong with a string so if something is wrong i want to set the BackgroundColor of this cell with the bad string to a color i can define.
    Do I need to write an own TableCellRenderer for this tiny task?
    Table class has no setBackground(new Color(22,22,22),posRow,posCol);

    http://forum.java.sun.com/thread.jspa?forumID=57&threa
    dID=606504this code is from your ColorRenderer class:
    public void actionPerformed(ActionEvent e)
                   Iterator it = colors.keySet().iterator();
                   while ( it.hasNext() )
                        Point key = (Point)it.next();
                        int row = key.x;
                        int column = key.y;
                        if (column == -1)
                             model.fireTableRowsUpdated(row, row);
                        else if (row == -1)
                             int rows = table.getRowCount();
                             for (int i = 0; i < rows; i++)
                                  model.fireTableCellUpdated(i, column);                              
              }you have set an ActionListener to the ColorRenderer class and put the actionPerformed method in it but compared to a JButton the actionPerformed method is called when i click the JButton but what you do in your code that the actionPerformed method is executed. I have deleted the whole actionPerformed method and the listener and still the cell is displayed with a color so was it for the blinking?
    And the method setBackground is nowhere called or run actively so is this method called internally by the ColorRenderer class? or is this method somehow called recursively as in the method setBackground I can see this method call:
    c.setBackground( (Color)o ); but i think this is another setBackground method right? because the first method i mentioned has 3 parameters not 1 parameter so where is the method setBackground with 3 parameters called actively in your code? i cant find anything. ok after examining again the c.setBackground( (Color)o ); is the one with 3 parameters ;-)
    public void setBackground(Component c, int row, int column)
              { that was set for the previous cell, so reset it here
                   if (c instanceof DefaultTableCellRenderer)
                        c.setBackground( table.getBackground() );
                   //  In case columns have been reordered, convert the column number
                   column = table.convertColumnIndexToModel(column);
                   //  Get cell color
                   Object key = getKey(row, column);
                   Object o = colors.get( key );
                   if (o != null)
                        c.setBackground( (Color)o );
                        return;
                   //  Get row color
                   key = getKey(row, -1);
                   o = colors.get( key );
                   if (o != null)
                        c.setBackground( (Color)o );
                        return;
                   //  Get column color
                   key = getKey(-1, column);
                   o = colors.get( key );
                   if (o != null)
                        c.setBackground( (Color)o );
                        return;
              }using your full code gives me a bug:
    when i double click in the first column to change some text doesnt matter which row then the selected cell gets a red border and the rest of the table freezes. When i exchange the order of the columns move column 1 to 2 and column 2 to 1 then the freezed table is working again?? could you help solving that problem else the cell color setting works fine for me :-) thank you very much!

  • Setting the background color of the selection when text selected (input TextField)

    My input TextField has a black background. The problem is,
    when some text is enter and then selected, the selection background
    color remains black and the selected text remains white. Because of
    this it's imposible to tell that the text has been selected. Is
    there a way to change the selection background color, or do I
    really have to write a custom textfield? :(

    Yes, I do have an additional attribute called "identity" which is set to the original table where it came from. The problem is that I do not know how to check for it in my renderer. I will post my renderer code here
    public class myTableRenderer extends DefaultTableCellRenderer{
    public Component getTableCellRendererComponent( JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column) {
    final Component component = super.getTableCellRendererComponent(table, value,isSelected,hasFocus, row, column);
    if ( value != null ) {
    if ( value instanceof String ) {
    String val = value.toString();
    if ( val.compareTo("DisplayKnown") == 0 ) {
    component.setBackground(Color.CYAN);
    else
    component.setBackground(Color.LIGHT_GRAY);
    } // end if value not null
    return component;
    } // end mytablerenderer
    What happens here, is that only the column with the identity value "DisplayKnown" gets the color blue. I would like to color the whole row with that column value to be Blue.
    Does this make sense??
    Thanks,
    npatel

  • 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

  • Help setting the background color in the browser

    I’m setting up my web pages to be 960 x 600 pixels (or possibly 960 x 660).  How do I define a background color for the overflow in case people are viewing on higher than 1024 x 768 resolution -  right now everything outside of my webpage shows up as the default white.
    Thanks

    Use CSS.
    body { background-color:heliotrope; }

  • Setting the background color

    Hi,
    I do not think this is possible, but want to ask if there is a simpler way to do this.
    The issue is... I have 12 columns and all the columns are displayed horizontally on the oracle forms 11g.
    I want that when a user clicks on the record the whole record gets highlighted.
    I know this can be achieved by doing the following for each and every item but I want to know if there is a way to highlight the whole record ?
    SET_ITEM_PROPERTY('item1',CURRENT_RECORD_ATTRIBUTE,'color'); Thanks
    Munish

    Create a new visual attribute with features you want in your record which is the current record and give it a meaningful name . Then just go to the property pallete of your data block if your data block shows you multiple records then just set a property named as CURRENT RECORD VISUAL ATTRIBUTE to the visual attribute which you had just created. It will work and I hope this helps. Cheers

  • Dynamically Set Subreport Background Color to the Same Value as Main Report Background Color

    I have a report that contains a subreport.  The main report has groupings in it.  I am dynamically setting the background color of the group rows based on an expression.  That part is working fine.  The problem that I am having is that
    I don't know how to get the subreport to "inherit" the background color of the grouping that holds it.
    Basically, I have different row shadings on my report differentiating the groupings except for the rows where the subreport shows.
    How do I go about setting the subreport background color to equal it's contaiing grouping's background color?  Thanks in advance for any and all assistance provided.

    The parameter method given by gpshukla will send the info to the subreport, but you don't need the color parameter in the main report, only the subreport. The trick is in setting the value of that parameter.
    Right-click the cell with the embedded subreport, you can select subreport properties.
    Select Parameters and add a parameter.
    The name column is the name of the parameter in the subreport (color) and value is the value to set it to.
    Set name to "color" (no quotes).
    Set Value to the same expression used to set the background color for the row.
    In the subreport, click the design surface to select the report (not header or footer).
    In the properties pane, select background color and choose expression from the dropdown.
    Type =Parameters!color.Value into the expression builder.
    This will work assuming that background color in the main report row will not change without also refreshing the subreport.
    "You will find a fortune, though it will not be the one you seek." -
    Blind Seer, O Brother Where Art Thou
    Please Mark posts as answers or helpful so that others may find the fortune they seek.

  • Setting JScrollPane background color.

    Does anybody know how to set what color appears in the background of a JScrollPane when the Component in the pane is smaller than the pane itself?
    In particular, I have a JTable in a JScrollPane, and when the pane is bigger than the table, the gray default background of the viewport looks weird behind the white background of the table.
    MyScrollPane.setBackground() doesn't do it, neither does MyScrollPane.getViewport().setBackground().
    Thanks in advance,
    Jason

    This might explain some things, hope it helps...
    it's a cut and paste from the JScrollpane source....
    A common operation to want to do is to set the background color that will be used if the main viewport view is smaller than the viewport, or is not opaque. This can be accomplished by setting the background color
    of the viewport, via scrollPane.getViewport().setBackground().The reason for setting the color of the viewport and not the scrollpane is that by default JViewport is opaque which, among other things, means it will completely fill in its background using its background color. Therefore when <code>JScrollPane</code> draws its background the viewport will usually draw over it.

Maybe you are looking for

  • Append a record to internal table

    hello: when i execute the code below,there is a runtime error." In die sortierte interne Tabelle (Typ SORTED_TABLE)   "PROGRAM=ZJOIN_INTER_TABLEDATA=T_ITAB1" sollte an Position 1 eine Zeile eingefügt bzw. geändert werden. Dadurch wurde die für die Ta

  • Problem to analyse mapping error

    Hi all, I have a problem to analyse a BPM mapping error on PI7.1. The szenario is as follows: I have 3 different containers (Abstract Interfaces) which data is used to determine the content of a  result container. E.g: ABSTRACT_INTERFACE_1 ABSTRACT_I

  • Change charset in Oracle 10g XE

    How do I change the charset to WE8ISO8859P1 in Oracle 10g XE ? thanks in advanced

  • How to for a newbie to LR

    I am new to LR 1.3.1. I am using Windows Vista. I have been away from photo editing and decided to jump back in with LR. I have the following questions/issues: I have saved files from camera onto a cd. I then imported the pics to LR. I then did neces

  • Tuxedo Service Debugging

    Hi All , Is it possible to debug Tuxedo Services using GDB in Unix environment (AIX) .. Could you please share your experience in this regard Thanks in advance Nadeer.