Display of text of different rows with different color - JTable

Hi all !
I have struck in a problem. I have to display the different rows with different color in the JTable. I have created an arraylist in the model class, which stores color of all the rows. Now in renderer class, I am just picking up color from the arraylist, taking rowIndex as index for arraylist. I used to set foreground color for each row in the renderer class. The problem is that it is not showing all the rows properly, sometimes it show all the rows correctly, but as i resize the window/panel, it starts behaving abnormally, some text is painted properly, but other aren't.
Does anybody have any solution regarding this problem.
One thing i want to mention is that in getTableCellRendererComponent() method, i used to retrive the color everytime, and setting the foreground color of the text. Is this a right approach or some other technique have to be followed.
here is code of renderer class ---
import java.awt.*;
import javax.swing.*;
* Renderer to plot stage record table.
public class ExStageCellRenderer extends javax.swing.table.DefaultTableCellRenderer
    Color curColor;
     * returns component to be painted, overridding this method from
     * DefaultCellRenderer
     * @param table
     *            table whose component has to be plotted
     * @param value
     *            value of that particular cell
     * @param isSelected
     *            is Cell selected
     * @param hasFocus
     *            has the cell got focus
     * @param row
     *            row of the cell
     * @param column
     *            column of the cell
     * @return painted component
    public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
            int column)
        Component component = super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column);
        ExStageDataModel model = (ExStageDataModel)table.getModel ();       
        if (curColor instanceof Color) {
                curColor = model.getColor(row);
            } else {
                // If color unknown, use table's foreground color
                curColor = table.getForeground();
        String tooltip = "";
        StringBuffer stringBuffer = new StringBuffer ();
        for (int i = 0; i < table.getColumnCount (); i++)
                Object Value = table.getValueAt (row, i);
                if (Value == null) continue;
                stringBuffer.append (Value.toString () + "    ");
        tooltip += stringBuffer.toString ();
        tooltip = tooltip.trim ();
        ((JComponent) component).setToolTipText (tooltip);
        if (column == 1)
            this.setHorizontalAlignment (SwingConstants.CENTER);
        else if (column == 0 || column == 4 || column == 5)
            this.setHorizontalAlignment (SwingConstants.LEFT);
        else
            this.setHorizontalAlignment (SwingConstants.RIGHT);
        // LOOK!! should turn tip off if there is none !!
        component.setForeground (this.curColor);
        //System.out.println("render : " + component.getBounds ());
        //component.validate ();
        component.update (component.getGraphics ());
        return component;
Waiting for reply....
Code snooker

Hmm, why are you doing the curColor instanceof? What does this accomplish? I don't see any reason to ask what it was before; all you should be interested in here is what you want it to be now.
All you should have to do is say:
this.setForeground(model.getColor(row));I also don't see why you're doing the update() -- JTable is going to do that for you at the appropriate time, you have no idea if now is the right time to do it or not. In fact it probably isn't, you're probably updating the previously-drawn cell with your new color and alignment, which may be the strange behavior you're seeing.
Also, I don't see why you're doing the super. All that's going to do is return "this", so why not just use "this"?
Well, without knowing your larger code or exactly what you're trying to accomplish, maybe I'm just missing something.
I've just recently been working on a program where I had some similar requirements -- different foreground and background colors and alignment -- and I found it much cleaner to create a class to hold all this data, and then create a default renderer for that class. Then I made some constructors for this "attribute" class that let me set whatever I need, like
public CellAttrib(String s,Color c,int alignment,Border border)
  this.s=s;
  this.c=c;
  this.border=border;
// with suitable defaults ...
pubic CellAtrtrib(String s)
  this.s=s;
  this.c=Color.BLACK;
  this.border=null;
}Then the renderer just queried the cell-attributes class, as in:
setForeground(value.getColor());
setHorizontalAlignment(value.getAlignment());
setBorder(value.getBorder);

Similar Messages

  • Not able to color different rows with different colors in a column of table

    Hi,
    I am trying to to display different rows with different colors in a column of the table based on some decode condition.
    I have gone through the following threads :
    Can we colour the rows in the column of a table
    Changing Color of a value in a column
    This is what i have done :
    1.Added the following code to custom.xss(changed the name to Custom.xss as suggested in one of the above threads) --- in path ---- jdev\myhtml\OA_HTML\cabo\styles
    <style selector=".1">
    <includeStyle name="DefaultFontFamily"/>
    <property name="font-size">11pt</property>
    <property name="font-weight">Bolder</property>
    <property name="color">#008000</property>
    <property name="text-indent">3px</property>
    </style>
    <style selector=".2">
    <includeStyle name="DefaultFontFamily"/>
    <property name="font-size">11pt</property>
    <property name="font-weight">Bolder</property>
    <property name="color">#FFFF00</property>
    <property name="text-indent">3px</property>
    </style>
    2. Sql query of the VO is :
    select comments,role ,decode(role,'REQUESTER','1','2') Colorattr from xxat_sars_action_history where request_id = :1 and event_name = :2 and action_code <> 'PENDING'
    order by sequence_num desc
    3. Coded the following in the process request of the controller:
    OATableBean table = (OATableBean)webBean.findIndexedChildRecursive("CommentsTB");
    OAMessageStyledTextBean roleBN = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("role");
    OADataBoundValueViewObject cssjob = new OADataBoundValueViewObject(roleBN,"Colorattr");
    roleBN.setAttributeValue(oracle.cabo.ui.UIConstants.STYLE_CLASS_ATTR, cssjob);
    where 1 and 2 form the colors ( i have even tried with 'Red' and 'Yellow'...as it was not working replaced with 1 and 2)
    4.The query returns data fine with corresponding 1 and 2 values.
    But different colors are not getting reflecting on to the UI.
    I am testing this on my local jdev.
    Please do let me know if i am missing something.
    Thanks ,
    Sushma.

    Any Clues please.....
    Thanks,
    Sushma.

  • Csv input adapter - read rows with different # of columns

    I have a csv file which includes rows with different number of columns. I want to read all the rows( of different # of cols)  into ONE stream only and then split into separate streams afterwards.
    I saw that CSV File Input Adapter does not add missing columns with nulls by default. Is it possible somehow? How can I generate a workaround?
    Thanks.

    Hello,
    The CSV Input Adapter expects to find a fixed number of fields.  If you attach the input adapter to a stream/window with 3 fields, it will always try to read three fields.  You can have missing data and this will be read into a column as a NULL value but the delimiters must still be there.  For example:
    1,1,1
    2,2,2
    3,3,3
    4,,4
    5,5,5
    CREATE INPUT WINDOW inWindow SCHEMA (c1 integer, c2 integer, c3 integer) PRIMARY KEY (c1);
    ATTACH INPUT ADAPTER File_Hadoop_CSV_Input2 TYPE toolkit_file_csv_input TO inWindow PROPERTIES csvExpectStreamNameOpcode = FALSE ,
      dir = 'c:/temp' ,
      file = 'test.csv' ,
      csvDelimiter = ',' ;
    A workaround you might consider is reading an entire line from your file into a stream with a single string column.  The trick is that you have to choose a character for the column delimiter that you are certain will never show up in your data.  Than once you have read that line into a stream, you can use the string functions to parse out the columns as needed:
    CREATE INPUT STREAM csv_instream SCHEMA (
      log_line_message string
    // Choose a character that is certain to never show up in the data in order to read the entire line
    // from the CSV file into a single column
    ATTACH INPUT ADAPTER File_Hadoop_CSV_Input1 TYPE toolkit_file_csv_input TO csv_instream PROPERTIES
      csvExpectStreamNameOpcode = FALSE ,
      dir = 'C:/temp' ,
      file = 'error_log' ,
      csvDelimiter = '@' ;
    // Parse out the individual columns
    CREATE OUTPUT STREAM csv_outstream SCHEMA (
      log_datetime timestamp ,
      debug_level string ,
      host string ,
      message string ) AS SELECT
      to_timestamp(substr(CI.log_line_message, 1, 24), 'DY MON DD HH24:MI:SS YYYY') as log_datetime,
      substr(CI.log_line_message, patindex(CI.log_line_message, '[', 2)+1, (patindex(CI.log_line_message, ']', 2) - patindex(CI.log_line_message, '[', 2))-1) AS debug_level,
      replace(substr(CI.log_line_message, patindex(CI.log_line_message, '[', 3)+1, (patindex(CI.log_line_message, ']', 3) - patindex(CI.log_line_message, '[', 3))-1), 'client ', '') AS host,
      substr(CI.log_line_message, patindex(CI.log_line_message, ']', 3)+1, 500) AS message
      FROM csv_instream CI
      WHERE CI.log_line_message IS NOT NULL;
    Thanks,
    Neal

  • Updating multiple rows with different values

    Hi!
    I have a problem. I need to update more then 1000 rows with different values. How can I do it?
    For exsample i have table:
    id; color, date,
    1 red
    2 green
    3 white
    I need to update date field.
    Update table
    set date='01.02.03'
    where id=1
    Update table
    set date='01.03.03'
    where id=2
    Maybe there is way how to update multiple rows at one query?
    Sorry for my bad english.
    Thanks!

    Hi,
    You can try this
    UPDATE TABLE SET DATE = CASE
                        WHEN ID = 1 THEN TO_DATE('01-02-03','DD-MM-RR')
                        WHEN ID = 2 THEN TO_DATE('01-03-03','DD-MM-RR')
                        ENDcheers
    VT

  • Query result Alternate row with different color   

    hello
    can anyone help me on a query result.
    i wish to have a :
    query result Alternate row with different color .
    ex.
    first row light grey
    second row darker grey.
    and repeats itself up to the last record/row.
    thanks

    <tr> <!------------------------------I replaced with
    <tr bgcolor="<cfif currentrow mod
    2>##D3D3D3<cfelse>##F5F5F5</cfif>">
    <td>
    #MYARRAY[x][2].CNO#
    </td>
    <td align="center">
    #MYARRAY[x][2].CDCDTt#
    </td>
    <td>
    #MYARRAY[x][2].PADESC#
    </td>
    <td align="center">
    #MYARRAY[x][2].INc#
    </td>
    <td align="center">
    #MYARRAY[x][2].Exp#
    </td>
    <cfset thirdArray = MYARRAY[x][3]>
    <cfif NOT arraylen(thirdArray)>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <cfelse>
    <cfloop index="z" from="1" to="3">
    <cfif z GT arraylen(thirdArray)>
    <td> </td>
    <td> </td>
    <cfelse>
    <td>
    #thirdArray[z][2]# 
    </td>
    <td>
    #thirdArray[z][3]# 
    </td>
    </cfif>
    </cfloop>
    <cfif arrayLen(thirdArray) gt 3>
    <td nowrap="nowrap">
    <cfloop index="z" from="4" to="#arraylen(thirdArray)#">
    #thirdArray[z][2]# - #thirdArray[z][3]#<BR />
    </cfloop>
    </td>
    </cfif>
    </cfif>
    </tr>
    I got this error.
    Variable CURRENTROW is undefined

  • Displaying remote panel on different screens with different screen resolution

    Hi
    I am running a vi on the PXI . But when i try to open the remote panel it gets shifted on different screens
    with different screen resolution. I have tried to set the windows run time position using the vi properies
    but to no avail. Can anyone help me on this issue??????
    Regards
    Amit Ahuja

    What is your lv version?

  • Help! Resizing different documents with different resolutions?

    Hello!
    Please help me with my situation:
    I was trying to make an action that will decrease 1 inch to all sides of my document (the document size was 12x36 inches) and hopefully to other documents.  I don't want to crop the image, I just want to resize the whole image to 10x24 inches, leaving a 1 inch transparent border (the gray and white checkerboard) to my document. I started resizing manually, but it was time-consuming so I tried to make the action I stated above. I was expecting that it would decrease a proportionate 1 inch to the top, bottom, left and right sides of other documents, but it didn't. Any procedure to make this happen in different documents with different sizes and resolutions?
    PS: All the the documents that I will resize would eventually be printed ( I don't know if this would help).
    Thank you for your help!

    Kursover wrote:
    I was trying to make an action that will decrease 1 inch to all sides of my document (the document size was 12x36 inches) and hopefully to other documents. I don't want to crop the image, I just want to resize the whole image to 10x24 inches, leaving a 1 inch transparent border (the gray and white checkerboard) to my document. I was expecting that it would decrease a proportionate 1 inch to the top, bottom, left and right sides of another document, but it didn't. Any procedure to make this happen in different documents with different sizes and resolutions?
    Easy to do in a script not so easy in an action unless you know that there is no background layer or that all have backgounds.  You can not add transparent canvas to a document with a background layer for brckground layers do not support transparence. Documents may or mant not have a background layer and background layers can be converted to a normal layer.  Actions can not use logic without using a script to see if there is a background.  My Crafting Actions package contains a utility script for actions that will convert background layers to a normal layer should a document have a background layer. Once you know there is no "Background" the rest is easy to do in an action with menu limage canvas size check relative and set width and height to 1" the will add 1"
    Decreasing -1" will CROP any layer the has not transparent pixels in the outter 1"
    Crafting Actions Package
    Contains
    Action Actions Palette Tips.txt
    Action Creation Guidelines.txt
    Action Dealing with Image Size.txt
    Action Enhanced via Scripted Photoshop Functions.txt
    CraftedActions.atn Sample Action set includes an example Watermarking action
    Sample Actions.txt Photoshop CraftedActions set saved as a text file.
    A script can retrieve the width and height of a document to changs size you need to resize the document this will not crop but will resample and you most matain aspect ratio elss resize will distort. Decreasing canvas size may crop...
    12 Scripts for actions
    Example
    Download

  • HT204053 i RECENTLY PURCHASED ANOTHER IPHONE.  MY INTERNET IS NOT WORKING.  I JUST CREATED AN APPLE ID.  WHAT'S NEXT?  I NOW HAVE TWO DIFFERENT ACCOUNTS WITH DIFFERENT USER NAMES.  HOW CAN I USE ONLY ONE ACCOUNT FOR ITUNES, ICLOUD APPLE ID ETC???

    I RECENTLY PURCHASED ANOTHER IPHONE.  MY INTERNET IS NOT WORKING.  I JUST CREATED AN APPLE ID.  WHAT'S NEXT?  I NOW HAVE TWO DIFFERENT ACCOUNTS WITH DIFFERENT USER NAMES.  HOW CAN I USE ONLY ONE ACCOUNT FOR ITUNES, ICLOUD APPLE ID ETC???

    Welcome to the Apple community.
    iTunes and iCloud and different accounts, you will need to delete both accounts from your device before adding the new details in their place.
    For iCloud go to settings > iCloud, scroll down and hit the delete button. You can then sign back in using your correct details. For iTunes go to settings >store, tap your account ID and then sign out, you can then sign back in using your correct Apple ID.

  • Can I use two different devices with different apple ID for backing up data on one machine without losing any data that was backed up with one device earlier?

    Can I use two different devices with different apple ID for backing up data on one machine without losing any data that was backed up with one device earlier?

    The link is to a discussion started on 12/18 in the FiOS Internet forum.  Here's the link I get now, however it is different than the link I pulled a few hours ago.  If this system changes the link again, it may not work.
    http://forums.verizon.com/t5/FiOS-Internet/Frustration-and-just-confused-with-internet-help-please/t...
    You can also look for the topic, "frustration and just confused" in the FiOS Internet forum.
    Here's a link that is in the thread that gives more detail.
    https://secure.dslreports.com/faq/15984
    Good Luck!
    P.S.  "Copper Contributor" is my "rank."  gs0b is my user name.
    If a forum member gives an answer you like, give them the Kudos they deserve. If a member gives you the answer to your question, mark the answer as Accepted Solution so others can see the solution to the problem.

  • Is it possible to have 2 icloud (from 2 different iphones with different apple ids) on the same computer?

    I am inquiring as to if you can 2 different icloud accounts (that come from 2 different iphones with different apple ids) on the same computer. I would like both iphones to be able to back up to the same computer since we have different accounts/pictures/mail etc.

    Yes, if you create 2 seperate user accounts.

  • Different templates with different datasource files

    Hi All,
    Can someone tell me how we can have two different templates with different datasource files in one BIP report.
    I need PDF template based on one xml file and CSV teamplate based on another in one report.
    Thanks.

    you can have two data-set or query , and select concatenated data and have a single xml file.
    But pdf template will look at those, dataset in the xml, which you want. and CSV will look only on the other dataset.
    what method are you using for CSV ?

  • Running different databases with different users OpenVMS?

    Hi,
    We run a few databases 9.2.0.5 in OpenVMS 8.2.
    Is there any problems running the different databases with different accounts?
    Anything to think about, more than to create a different account with same credentials as the original ORACLE user?
    BR
    BjörnR

    Hi,
    I'm not sure if I understood your question, but from my experience I can tell that YES, you can have different accounts - belonging to the same DBA group - on different oracle installations and this can be the case even if you're running a cluster.
    Hope this helps.
    Regards,
    Naveed.

  • I have published two different blogs with different usernames and passwords

    I have published two different blogs with different usernames and passwords. When I want to publish one, it goes through the whole process of publishing the other blog as well - and takes too long.
    How can I publish each blog separately?

    I have published two different blogs
    I think you need to ask in the iWeb forum rather than this one (for iWork/Numbers):
    http://discussions.apple.com/forum.jspa?forumID=1309

  • HT204053 Can you sync pages files on different devices with different apple ids?

    Can you sync pages files on different devices with different apple ids?  I have a personal iPad and one given to me for work. They are set up with two different apple IDs.  I do all of my lesson plans in pages.  I want to be able to create plans on both devices, but need to know if there is a way to sync the files without emailing, etc.

    Welcome to the Apple Community.
    No, that's not possible. A better way of working around this than emailing the documents to yourself is to use a third party storage solution such as Dropbox and a webDAV server to upload the documents.

  • How to paste text in Adobe Muse with same color where i copied this text?

    How to paste text in Adobe Muse with same color where i copied this text?

    Copy&paste is a function of your browser, not the forum software. Ctrl+V will work just fine.
    Mylenium

Maybe you are looking for

  • Office 2010

    office 2010 came installed on my computer.  somehow i lost it ( computer was worked on by hp support, i think in sept.)   i tryed to open some of my documents today dec 13 2013 & could not. i can't find the key to re-install.  how can i recover the k

  • DBMS_XMLDOM.WRITETOFILE overloading

    Hello all. Quick question. I'm running into memory issues when creating my xml file using the DBMS_XMLDOM oracle 9i package. I'd like to write out the file initially and then append to it using DBMS_XMLDOM.WRITETOFILE throughout my program. Similar t

  • Enabling Arabic Language

    I have installed Oracle 9i database, I need to change the charater set which should enable me to save data in Arabic language, where as currently it saving in Junk Language, I woudl like to know is there any way that i can change some settting in dat

  • Camtasia SWF and Robohelp x5 - Please help!

    I think the summary says it all. I produce a swf file using Camtasia (a well known and popular video producer) and when I include all the video files in the project, nothing shows up after it's compiled (there are 4 files: an swf video, controller ht

  • Mayor Problems with new installation / restoring from time machine

    I encountered several problems while setting up my mac mini, 1,66 Ghz, 60 GB from the start. The following problems occured: 1.) Installing 10.6 upon existing 10.6.4 caused scanner driver to fail. I was unable to reinstall it, so i decided to reinsta