Change particular cell color when finised editing and when lost focus

Hi, i want to create a table which its particular cell can change its color automatically to red if the value in cell in column in two is smaller than column cell value in column 1 when user finish typed a value or if the cell has lost focus. I've wrote a code for the renderer but how should I use action, KeyListener or MouseLister or both
* File ColouredCellRenderer.java
import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.DefaultTableCellRenderer;
public class ColouredCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer{
    private Object col1Value, col2Value;
    public ColouredCellRenderer(Object args1, Object args2){
        this.col1Value = args1;
        this.col2Value = args2;
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
          return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     protected void setValue(Object v){
          super.setValue(v);
        if((col1Value != null) & (col2Value != null)){
            int x = Integer.parseInt(col1Value.toString());
            int y = Integer.parseInt(col2Value.toString());
            if(x > y){
                this.setBackground(Color.RED);
            else{
                this.setBackground(Color.GREEN);
}

All you should need is the cell renderer to achieve that effect. Whenever the table needs to render a cell it will call the method
getTableCellRendererComponent(...);This method in turn returns a component showing what the cell should look like. The DefaultTableCellRenderer extends JLabel, so you are meant to customize the label (based on parameters that were passed) and return this* at the end of the method.
public Component getTableCellRendererComponent(...) {
         return this;
}This one label is used to render all the cells of all the columns that the cell renderer is assigned to. Since you want some cells too be red, you should call setBackground(Color.red)+ when the conditions are appropriate or null otherwise.

Similar Messages

  • How do i change the cell color of each cell in datagrid dynamically

    I have a  datagrid filled in with data..My job is to change the cell color of a particular cell in the datagrid when the user clicks that cell..Please help me asap..I have to change the color of each cell dynamically..

    Pls find the solution of ur problem.Let me know if you have any issue.
    MainApplicaion.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical">
        <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.events.ListEvent;
                [Bindable]
                  private var listDataArrayCollection:ArrayCollection=
                  new ArrayCollection([
                    {seq:'1',color:'0xFF0000', names:'John'},
                    {seq:'2',color:'0x00FF00', names:'Alex'},
                    {seq:'3',color:'0x0000FF', names:'Peter'},
                    {seq:'4',color:'0xFF0000', names:'Sam'},
                    {seq:'5',color:'0x00FF00', names:'Alis'},
                    {seq:'6',color:'0x0000FF', names:'Robin'},
                    {seq:'7',color:'0xFF0000', names:'Mark'},
                    {seq:'8',color:'0x00FF00', names:'Steave'},
                    {seq:'9',color:'0x0000FF', names:'Fill'},
                    {seq:'10',color:'0xFF0000', names:'Abraham'},
                    {seq:'11',color:'0x00FF00', names:'Hennery'},
                    {seq:'12',color:'0x0000FF', names:'Luis'},
                    {seq:'13',color:'0xFF0000', names:'Herry'},
                    {seq:'14',color:'0x00FF00', names:'Markus'},
                    {seq:'15',color:'0x0000FF', names:'Flip'},
                    {seq:'16',color:'0xFF0000', names:'John_1'},
                    {seq:'17',color:'0x00FF00', names:'Alex_1'},
                    {seq:'18',color:'0x0000FF', names:'Peter_1'},
                    {seq:'19',color:'0xFF0000', names:'Sam_1'},
                    {seq:'20',color:'0x00FF00', names:'Alis_1'},
                    {seq:'21',color:'0x0000FF', names:'Robin_1'},
                    {seq:'22',color:'0xFF0000', names:'Mark_1'},
                    {seq:'23',color:'0x00FF00', names:'Steave_1'},
                    {seq:'24',color:'0x0000FF', names:'Fill_1'},
                    {seq:'25',color:'0xFF0000', names:'Abraham_1'},
                    {seq:'26',color:'0x00FF00', names:'Hennery_1'},
                    {seq:'27',color:'0x0000FF', names:'Luis_1'},
                    {seq:'28',color:'0xFF0000', names:'Herry_1'},
                    {seq:'29',color:'0x00FF00', names:'Markus_1'},
                    {seq:'30',color:'0x0000FF', names:'Flip_2'}
                private function onItemClick(event : ListEvent):void
                    var dataObj : Object = event.itemRenderer.data;
                    dataObj.color = "0xFF00FF";
                    event.itemRenderer.data = dataObj;
            ]]>
        </mx:Script>
        <mx:VBox width="300" height="100%"
            horizontalAlign="center"
            verticalAlign="middle">
            <mx:DataGrid id="listComponent" width="50%"
                     height="100%"
                     borderStyle="none"
                     dataProvider="{listDataArrayCollection}"
                     itemClick="onItemClick(event)">
                     <mx:columns>
                     <mx:DataGridColumn width="100" dataField="{data.seq}" headerText="Seq" itemRenderer="SeqItemRenderer" />
                     <mx:DataGridColumn width="100" dataField="{data.names}" headerText="Name" itemRenderer="NameItemRenderer"/>
                     </mx:columns>
                     </mx:DataGrid>
        </mx:VBox>
    </mx:Application
    NameItemRenderer.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
        width="100" height="30" horizontalGap="5" horizontalScrollPolicy="off">
    <mx:Script>
        <![CDATA[
            override public function set data(value:Object):void
                 super.data = value;
        ]]>
    </mx:Script>
            <mx:TextInput width="75" height="30"
                 text="{data.names}"
                 editable="false" backgroundColor="{data.color}"/>
        </mx:HBox>
    SeqItemRenderer.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
        width="100" height="30" horizontalGap="5" horizontalScrollPolicy="off">
    <mx:Script>
        <![CDATA[
            override public function set data(value:Object):void
                 super.data = value;
        ]]>
    </mx:Script>
            <mx:TextInput width="75" height="30"
                 text="{data.seq}"
                 editable="false" backgroundColor="{data.color}"/>
        </mx:HBox>
    with Regards,
    Shardul Singh Bartwal

  • Change the cell color in JTable?

    Hi all,
    I'm trying to do that, the user make a selection of multiple cells in a table. And when it press enter, I whant to change the color of the selected cells.(the isEditable of JTable it's already overwritten to return always false)
    I have already make my own CellRender, my problem is, because the cell remains unchanged the render are not called...
    Thanks,
    NeuralC

    You need not access this function when you want to paint a cell. This is how your code while instantiating the table should typically look like.
    JTable table = new JTable(model);
    table.setDefaultRenderer(Object.class,new MyCellRenderer());
    and
    public class MyTableCellRenderer extends JLabel implements TableCellRenderer
    public MyTableCellRenderer
    setOpaque(true);
    setBackground(Color.white);
    public Component getTable.....(JTable table,Object value,......) //fill all these things
    setFont(table.getFont());
    if(value != null && isSelected)
    setHorizontalAlignment(SwingConstants.RIGHT);
    setText(value);
    return this;
    When you set MyTableCellRenderer to the table, the getTableCellRedererComponent method is called automatically to renderer the cells and only the selected cells will be hightlighted in blue color. For a better understanding of how tables work and their corresponding Renderers work, you might have to read the tutorial on JTable. Do that as that would help you in removing all the confusion.
    Thanks,
    Kalyan

  • I have change e-mail address after first registration and when I logged in it send new password to my old e-mail address. now I can't use my old profile

    I have change e-mail address after first registration and when I logged in it send new password to my old e-mail address. now I can't use my old profile.
    and I can't install my old adobe X anymore
    what to do?
    Mika

    Change Account https://forums.adobe.com/thread/1465499 may help
    -wrong email https://forums.adobe.com/thread/1446019

  • When I edit and/or delete photos from an album in iPhoto is there a way to make that what happens in the folder in finder?

    When I edit and/or delete photos from an album in iPhoto is there a way to make that what happens in the folder in finder? I am new to Mac. I've updated the operating system and iPhoto.

    If your iPhoto Advanced preference pane is setup like this
    all photos you import into the library are COPIED into the library.  Thus those photos in the folders outside of iPhoto are redundant and can be deleted to save space on your hard drive. There no need to keep those copies in the folders.
    If you do have your advance preferences set as shown above you can access your photos for use outside of iPhoto according to the following User Tip by Terence Devlin which is the best treatise on how to access photos (for use outside of iPhoto):  How to Access Files in iPhoto.  Otherwise you access your photos from within iPhoto. 

  • I bought htc 8x verizon employee edition and when i update it and during installation with my error phone get off and now phone stuck on some wheel running thing and wont get on please tell me if i could download the rom

    i bought htc 8x verizon employee edition and when i update it and during installation with my error phone get off and now phone stuck on some wheel running thing and wont get on please tell me if i could download the rom or anything also

        Hi mnomi! Sorry to learn of the trouble you're running into with your new phone! Have you already switched the device via your My Verizon : http://vz.to/16lkVUY Once you have done this, and verify the sim card is inserted securely, the activation will begin. If the phone is stuck on the wheel and you cannot move forward, you may want to do an alternative reset. Please follow the below instructions:
    1) Ensure the device is powered off.
    2) Press and hold the Volume Down button (located on the right edge) until instructed to release in step 4.
    3) Press and hold the Power button (located on the top-right edge) until the device vibrates (approximately 2 seconds) then release.
    4) When the restore screen appears (exclamation mark), release the Volume Down button.
    5) From the restore screen, press then release the following keys to initiate the reset process:
    1. Volume Up button
    2. Volume Down button
    3. Power button
    4. Volume Down button
    *Allow several minutes for the process to complete (rotating gears appear on the display to indicate that the reset is in progress).
    If you have any further questions or concerns, please let us know. Keep us posted if this resolves your concerns. Thanks!
    -KristieQ_VZW
    Follow us on Twitter @VZW Support

  • I get Singed out of eBay when I bid and when I go to a other item.. I can be on "my eBay" and just click on any other item and boom I'm on a page that says I need to sing in.

    I get Singed out of eBay.com when I bid and when I go to a other item.. I can be on "my eBay" and just click on any other item and boom I'm on a page that says I need to sing in..if I click back it brings me back to "my eBay" and I am still singed in but if I was not to click back and I click on sing in I have a page saying I singed out.. sooo I do the obvious and clean out the cache and so on, disable all and then just some addons and try again and just to be sure I opened IE9 for the first time ever on this year old pc and it works fine so I know the problem is with FF4 but I'm out of ideas so what are my options? I dont wanna have to use IE9 but I need basic stability!!
    I give a A- on the rest of FF4 & that makes this even more annoying because I want to use FF4!! I make my butta on eBay.com so I'm on all day buying & selling so I really need a quick fix or I'll have to make a quick move to Opera or IE9..PLEASE DON'T LET THAT HAPPEN...LOL!!
    Please help me on this one & Thank you in advance to anyone who helps me I appreciate it allot!

    The Get Info. fields show up gray if the files is locked and iTunes knows it can't edit the file. Make sure the files are not marked as read only and, if necessary grant both your account and system full access to all files and subfolders of your media folder.
    You can set Part of a Compilation for multiple tracks from the Options tab of Get Info.
    See Grouping tracks into albums for tips on getting iTunes organized.
    tt2

  • I don't hear when i call and when i receive calls

    I don't hear when i call and when i receive calls. I already formatted my iphone but nothin changed... I hear and i'm heard with headphones and loudspeaker, that's all. Who can suggest me a way to get resolved this issue?

    Sounds like there's a hardware issue with your mic and receiver(speaker used to hear people when in a call).  If you've already restored the phone as new and you're still having the same problem, you need to look at repair/replacement options.  If you are still under warranty(within 1 year of original purchase date) and there is no accidental damage to the phone, Apple will replace it at no cost.  If you are outside your warranty then Apple will do an Out Of Warranty replacement, which will cost you $199 for another 4S.

  • I used to see my contacts' photos full screen when they called or when I called them now I only see a thumbnail when they calling and when I call them?

    I used to see my contacts' photos full screen when they called or when I called them now I only see a thumbnail when they calling and when I call them?
    iPhone 4s iOS 7.1

    Hello User909807,
    After having some close calls with fraudulent purchases on my own bank account, I know how scary it can be to know someone else other than you had your personal information, so it was nice to know my issuing bank was helping keep my identity safe. Having said that, it’s completely understandable why it’d be frustrating to discover you were unable to continue making purchases after confirming your identity via text, and I apologize if this caused any unintentional frustration.
    While I’ll be sure to document your feedback regarding our partnership with Citibank, N.A., please know that they are the issuer of your My Best Buy credit card account. As such, I will be glad to share your concerns with our Citibank contacts so that they may contact you to discuss your account in further detail. Please know you should receive follow-up contact from them within the next 3-5 business days.  
    Respectfully,
    Alex|Social Media Specialist | Best Buy® Corporate
     Private Message

  • Hello..i have the macbook pro and i had a password when it opens and when i have updated the software when i delete something it asks me every time to put my password ;/ how do i delete my password or just correct a setting for it?

    hello..i have the macbook pro and i had a password when it opens and when i have updated the software when i delete something it asks me every time to put my password ;/ how do i delete my password or just correct a setting for it?

    You may need to rebuild permissions on your user account. To do this,boot to your Recovery partition (holding down the Command and R keys while booting) and open Terminal from the Utilities menu. In Terminal, type:  ‘resetpassword’ (without the ’s), hit return, and select the admin user. You are not going to reset your password. Click on the icon for your Macs hard drive at the top. From the drop down below it select the user account which is having issues. At the bottom of the window, you'll see an area labeled Restore Home Directory Permissions and ACLs. Click the reset button there. The process takes a few minutes. When complete, restart.   
    Repair User Permissions

  • What does it mean when screen lightens and when restarted it is pink, then grey and then normal

    what does it mean when screen lightens and when restarted the screen is pink and then grey and then normal..also the screen is slow to come up when i first open the laptop cover. thanks, lapapple

    Reset PRAM.  http://support.apple.com/kb/PH4405
    Reset SMC.     http://support.apple.com/kb/HT3964
    Choose the method for:
    "Resetting SMC on portables with a battery you should not remove on your own".

  • WD Tut18: when to bind and when to addElement() ???

    Hi All,
      I am trying <b>Context Programming and Data Binding (18) tutorial</b>.
      I am slight confused.. when to bind() and when to addElement()'s:
    page 22>>
    newCustomerNodeElement.nodeAddress().bind(newAddressNodeElement);
    page 26>>
    node.addElement(newOrderNodeElement);
    page23 explanation >>
    Note that, if you call the method bind (newCustomerNodeElement) instead of addElement(newCustomerNodeElement), only the last bound node element of the type Customer is contained in the list of node elements. That is, wdContext.nodeCustomers().bind(newCustomerNodeElement) overwrites the list of node elements of the type Customer.
      Is it that .. when the cardinality is 0..1 (or) 1..1>> we have to <b>bind</b> elements and when cardinality 0..n (or) 1..n >> we have to <b>addElement();</b> ??
      Also i didn't get the exact advantage of a supplyFunction.
    Can any1 help me out ?? explain me .. more detailedly ???
    Thank u very much in advance,
    kanth.

    Beginner,
    In general, bind and addElement are interchangeable: you may either bind or addElement.
    For example, if cardinality is 0..1 you may add sole element or bind this element. If the cardinality is 0..n then you may either bind collection of elements or add elements one by one.
    Typically, bind is used when you populate node content initially, addElement is used when user adds/removes already populated node.
    VS

  • How do I change the default color (gray) that 'Edit - Find' uses?

    When I search for a key word in a PDF file viewed in Safari web page using Edit -> Find 
    It defaults to highlighting the text it finds in light gray which is very hard to see. I would like to change the highlight color to something much easier to see on the page - like red for instance.

    What version of Pages & what version of OS X are you using?
    A problem with an early Software Update for Snow Leopard caused a lot of problems. The problem is not whether or not your system is the current version but how it got there. You must use the combo updater, not the one from Software Update unless it specifically states it is the combo. Software Update will only offer the combo if your system is two or more versions behind.
    If you're not running the latest versions of the iWork apps & Software Update says your software is up to date, make sure the applications are where the installer initially put them. The updaters are very picky. If the location is not where the updater is programmed to look or if the folder doesn't have the name the updater looks for, it will not work. The applications cannot be renamed or moved. If you installed from the downloaded trial or the retail box, they must be in the iWork '09 (or '08 if that's what you're using) folder in Applications. That iWork folder must be named iWork '09. If it doesn't have the '09 Software Update won't find them & the updaters won't work.

  • How to programmatically change the cell color of an ADF table ?

    Hi all,
    I have an ADF table with some fields on it. Depending on the value of a field named, say, "F1", I would like to change its background color.
    So far I can change the field color with this EL expression inside the InlineStyle table column property:
    font-size:medium; background-color:#{viewScope.myBean.setColor};
    where setColor is a bean function, in where I access the field "F1" via binding, parse its value, and return the right value - so far, so good.
    The bad thing is, the InlineStyle affects that field in all the rows of the table, while I would like to change only the field in the rows, which have that specific value in it.
    So for example having the rows:
    F1
    abc#1 ----> currently selected row
    cde#2
    efg#3
    I want to change the background color to all the F1 fields which have a "1" after the '#' and let the other "F1" row cells background color stay unchanged.
    But as you can imagine, the InlineStyle affect the "F1" background color in all the rows (assuming that the first row of the table is selected).
    So the question: how to access a single cell of a row in an ADF table, and programmatically change its background color ?
    So far I can iterate through the ADF table with:
    BindingContext bindingctx = BindingContext.getCurrent();
    BindingContainer bindings = bindingctx.getCurrentBindingsEntry();
    DCBindingContainer bindingsImpl = (DCBindingContainer) bindings;
    DCIteratorBinding dciter = bindingsImpl.findIteratorBinding("aTableIterator");//access the iterator by its ID value in the PageDef file
    RowSetIterator rsi = dciter.getRowSetIterator();
    System.out.println("rsi getrowcount = " rsi.getRowCount());+
    Row row = null;
    +if (rsi.getRowCount() > 0) {+
    row = rsi.getCurrentRow();
    System.out.println("row attr = " Arrays.toString(row.getAttributeNames()));+
    System.out.println("class : " row.getAttribute("F1").getClass().toString());+
    +}+
    +while (rsi.hasNext()) {+
    row = rsi.next();
    System.out.println("row attr = " Arrays.toString(row.getAttributeNames()));+
    +}+
    Regards,
    Sergio.

    Hi,
    I mean a specific cell within a row.
    Here are two pictures that show an ADF table with two rows and some fields on it:
    https://skydrive.live.com/?cid=7D3084D8BF755808&id=7D3084D8BF755808!107&sc=documents#cid=7D3084D8BF755808&id=7D3084D8BF755808!107&sc=documents
    bild_A is what I have, bild_B is what I would like. Note that:
    in bild_A the first row contain a yellow background color for the field F4 and an orange background color for the field F5. This is correct, because F4 has an "1" at the end of its string value, and F5 has a "3" at the end. So far so good.
    But the second row (again, bild_A) has also the fields F4 with yellow background color, and the field F5 with orange background color, even if the value in both fields is 0.
    What is should be, is shown in bild_B.
    The problem is that the solution provided affects all the cells of the column, while I need to change the background color of a single cell, and leave the other unchanged (see bild_B).
    I hope that clarify a bit :)
    Sergio.

  • Set the name of cell or cells' range for a report and when export it to excel the names will be defined.

    Hello,
    I have an C# application that exports report from Reporting Services to Excel files.
    I would like to know if there is a possibility to set the name of the cell or range of cells in the report (via Report Builder or somewhere else) and when open the Excel the names are set. Similar functinality when you open the Excel and go Formulas/Define
    Name and set the name for a unique cell or range.
    Regards,

    Hi there,
    I don't believe this is possible in Reporting Services.  One workaround, if you don't know the exact range at runtime, might be to put hidden characters (white?) in your sheet at start and end of range, then do some postprocessing on the file using
    VSTO or perhaps a 3rd-party tool like this one.  
    http://www.aspose.com/reporting-services/excel-component.aspx
    If you do know the range it should be much easier.
    cheers,
    Andrew
    Andrew Sears, T4G Limited, http://www.performancepointing.com

Maybe you are looking for

  • How to change language settings on the latest version of pages?

    How can I change languages in Pages?

  • Using 'Function Returning SQL Query' with Flash charts

    I have created a pl/sql function that returns a SQL query as a varchar2 of this form: select null link <x value> value <Series1 y value> Series 1 Label <Series2 y value> Series 2 Label <Series3 y value> Series 3 Label from tablea a join tableb b on a

  • Color Photo

    Every once in a while I see someone has posted a picture to a site where they can get help with a technique. In addition to the black and white question I previously posted, I have a color photo that I really like but it's not a high quality photo. I

  • Facing problem in Printing network shop papers.

    Hi Iam facing a problem in printing Network shop papers T-code CN22/CN23 after entering in to network in CN22/CN23 select menu path as below path : Network - Print - Shop papers we have many network in a project , there we are printing shop papers fo

  • ALV Control and Classical ALV

    Hi all, Please let me know the advantages and disadvantages of ALV control over Classical ALV. Thanks & regards, Naresh.