JTable: After one row is modified, the row should have red color background

After one row is modified(using setValueAt()),
I want the modified row to have red color background color.
How can I do that? I tried.
JTableInstance.setBackground( Color.RED);But it sets all the rows not the only modified row.

import java.awt.*;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.table.*;
public class TableChangeTest extends JFrame {
    public TableChangeTest() {
        initComponents();
        renderer = new MyTableRenderer();
        table.setDefaultRenderer(String.class, renderer);
        int row = 0;
        table.setValueAt("test1",row,0);
        rowsChanged.add( row );
        row = 2;
        table.setValueAt("test2",row,1);
        rowsChanged.add( row );
    private void initComponents() {
        panel = new JPanel();
        scrollPane = new JScrollPane();
        table = new JTable();
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("Table Change");
        panel.setLayout(new BorderLayout());
        table.setModel(new DefaultTableModel(
                new Object [][] {
                    {"1", "a"},
                    {"2", "b"},
                    {"3", "c"},
                    {"4", "d"}
                new String [] {
            "Title 1", "Title 2"
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
        scrollPane.setViewportView(table);
        panel.add(scrollPane, BorderLayout.CENTER);
        getContentPane().add(panel, BorderLayout.CENTER);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-357)/2, (screenSize.height-241)/2, 357, 241);
    public static void main(String args[]) {
        new TableChangeTest().setVisible(true);
    private JPanel panel;
    private JScrollPane scrollPane;
    private JTable table;
    private TableCellRenderer renderer;
    private ArrayList rowsChanged = new ArrayList();
    class MyTableRenderer extends DefaultTableCellRenderer {
        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.white );
            if( rowsChanged.contains(row) ) {
                setBackground( Color.red );
            return this;
}

Similar Messages

  • No rows to modify -- the row enclosing tag missing.

    I'm using the XDK in Java to process a number of XML files, loading into an Oracle DB relational table. I use OracleXMLSave.setXSLT to set a stylesheet to transform the input XML into the desired form for OracleXMLSave.insertXML and use OracleXMLSave.setRowTag to identify the row element in the transformed XML. I want to process all XML files in a single transaction (all or none get loaded).
    The problem I am having is that some of the XML files do not have any rows to insert (they have content, but not the desired content). The XSL file creates a valid XML document with no rows. However, when processed by OracleXMLSave.insertXML, the following exception results:
    Exception in thread "main" oracle.xml.sql.OracleXMLSQLException: No rows to modify -- the row enclosing tag missing. Specify the correct row enclosing tag.
    This causes processing to terminate, rolling back all previous inserts. I also tried modifying the XSL to create an empty row element. I would like a way to tell insertXML that rows may not exist in the input XML and that an exception should not be created for this. Anyone know a way to do this? Currently, I am trying to preprocess the files to make sure there will be rows before calling OracleXMLSave.insertXML.
    Thanks,
    John

    Read the FAQ, do some searches for something like OraclePreparedStatememt..
    Message was edited by:
    mdrake

  • TS1388 After one or two websites the search "freezes". To rectify this I need to go into "Network" and press "Renew DHCP Lease" on my imac 10.6.8

    After one or two websites the search "freezes". To rectify this I need to go into "Network" and press "Renew DHCP Lease" on my imac 10.6.8TS1317 - Mac OS X: Troubleshooting a cable modem, DSL, or LAN Internet connectionAny help?

    Check your computers time and date are correct, and updating to your location via Apple's servers.
    WiFi, Internet problems, possible solutions

  • How do I get rid of the blank space after one paragraph and before the next paragraph startsin Pages '09?  I understand that I should not have a page break mid paragraph but that is what I want.

    How do I get rid of the blank space after one paragraph and before the next paragraph startsin Pages '09?  I understand that I should not have a page break mid paragraph but that is what I want.

    Hi stephanie,
    These are unrelated questions/statements.
    Space before and space after a paragraph are controled in the Text Inspector, as you've found out.
    Pages will create a page break whenever there is no room for another line on the page. That break can come anywhere in a paragraph.
    You may be thinking of Widow and Orphan prevention, and the other Pagination controls, found under the More button in the Text Inspector. (If that's what you found, then thanks for the refresher! I hadn't been to that pane for awhile, and had forgotten the variety of pagination controls available.
    Regards,
    Barry

  • When i play my song after one or two min the voice becomes vibrated

    hi when i play my song after one or two min the voice becomes vibrated not well,please solve my problem. 

    Do you have repeat on? You can check this in now playing screen. Tap once at the centre of the screen, make sure the leftmost icon below scrub bar is not blue in color.

  • I have one apple id, but the family all have ipods, imac and mac book connected to this account. how do i face time them?

    i have one apple id, but the family all have ipods, imac and mac book connected to  this account. how do i face time from one device to another?

    Hello chlanli
    You would need to use one Apple ID for purchases in order to get them across all of your devices and computer. If you want you can use one Apple ID for purchases and the other one to sync personal data. The article below will explain further.
    Using your Apple ID for Apple services
    http://support.apple.com/kb/ht4895
    Regards,
    -Norm G.

  • Why I cant view my picture on my iphoto and if I try to copy to any folder it Shows "The item on the clipboard cant be pasted to this location. (One or more of the item may have been deleted or are no longer available) "

    Why I cant view my picture on my iphoto and if I try to copy to any folder it Shows "The item on the clipboard cant be pasted to this location. (One or more of the item may have been deleted or are no longer available) "

    There are 9 different versions of iPhoto and they run on 9 different versions of the Operating System. The tricks and tips for dealing with issues vary depending on the version of iPhoto and the version of the OS. So to get help you need to give as much information as you can. Include things like:
    - What version of iPhoto.
    - What version of the Operating System.
    - Details. Describe the problem as fully as you can. For example, if you have a problem with exporting, then explain by describing how you are trying to export, and so on.
    - History: Is this going on long? Has anything been installed or deleted? - Are there error messages?
    - What steps have you tried already to solve the issue.
    - Anything unusual about your set up? Or how you use iPhoto?
    Anything else you can think of that might help someone understand the problem you have.

  • Cant send mms messages. I get the error message:  "one or more of the message components have been delted by MMS Adaptation.  Either the message was too large or the components were unsuitable for your handset".  This only seems to be an issue to iphones.

    I cant send pic messages to iphone users. I get the error message:  "one or more of the message components have been delted by MMS Adaptation.  Either the message was too large or the components were unsuitable for your handset".  This only seems to be an issue to iphones.  I like this phone but have had nothing but trouble since day one.  I am so tired of being on the phone with verizon and still not getting all the problems corrected.  Someone please help!

    Hello christina267,
    Help is right here, front and center! Let's get your mms working properly. May I ask are you using the original stock messaging app to send texts and mms? Also, are you using any special characters or emojis in your message? Since you state that the issue is to iPhones, did you happen to have used an iPhone on your mobile number just before you were using the Galasy S 5? As you share the details then we can investigate.
    Thank you… 
    ArnettH_VZW
    Follow us on Twitter @VZWSupport

  • I have my catalog "Back Up Each Time Lightroom Exits" checked, and always have. That means the catalog should have been backed-up and saved everyday, if not more than once on some dates. So with a a major problem now and needing to use the Catalog backup

    I have my catalog "Back Up Each Time Lightroom Exits" checked, and always have. That means the catalog should have been backed-up and saved everyday, if not more than once on some dates. So with a a major problem now and needing to use the Catalog backup from last Friday, I go to my Lightroom Backups folder - and the most recent one showing not only isn't yesterday, it's OCTOBER 28 !?? Where the hell are the daily backups between October 28 and November 14?

    Oh wow - JET LAG strikes agin - my apologies; I have located the missing weeks of back-ups. After getting home from a 30-day trip to Europe, I had changed the location of my LR catalog back-ups to an external drive, and forgot that I did that. I have found them, and all is good. Never operate Heavy Machinery without enough rest. Cheers

  • I've just brought some video from itune, but realised the I should have brought the SD version instead of HD version as my iPad didn't have enough storage. Can I change that from HD to SD?

    I've just brought some video from itune, but realised the I should have brought the SD version instead of HD version as my iPad didn't have enough storage. Can I change that from HD to SD?
    Does it mean that I can't watch it if I cannot download it?

    this helps. check it out! http://support.apple.com/kb/ht3209

  • How to lock the rows in a transaction so others cant modify the rows

    Hi,
    I want few suggestion in the following scenario .
    I have a few records ( say 100 ) in a table which Im sending to the client over a network and are populated in a swing GUI...Now the client selects few of them ( say 3 ) and submits to the server. Now the server should assign a number to those rows and store them in the database. As it is a multi client environment While assigning the number it should check that no other client has already assigned a number to at lease to one of the row in the meantime. in that case it shoudl fail.
    In this case i want to lock those 3 records when the request arrives at the server assign number commit and release the lock.
    I want to avoid deadlocks.
    Can any one suggest me whoch locking policy should i use and how ?
    Thanx in advance...
    Mahi

    It depends on how acceptable it is for your commit to fail. By far the easiest and safest thing to do is use Optimistic Locking. This way if the server tries to commit changes to something that has already been committed, an Optmistic Lock exception will be thrown. It's up to your application to handle this, and depending on your domain and the likelyhood of this happeneing, you could just tell the user "try again". The other option is pessemistic locking, which is very, very, dangerous (in my opinion). The main issue is that it's resource intensive, and different databases have different semantics on how it works.
    IIWY, I'd look at Optimistic Locking in the docs and go from there.
    - Don

  • Refresh jTable after inserting new data into the Database

    Hey all,
    I'm using Netbeans 6.5 to create a Desktop Application which is connected to a Java DB (Derby).
    The first simple steps were all very successfull:
    Create the jTable and bind it to the Database => everything works fine. When the application starts it correctly shows all data from the database.
    The problem starts when I try to insert new data to the database.
    For that reason I've created textfields and a button "Save". When I press the button it successfully inserts the data to the database but they are not displayed in the jTable (when the application starts they are all there, they are not updated at runtime) . I've tried table.invalidate() and table.repaint() but they just don't work.
    Any help will be GREATLY appreciated. But please have in mind that most of the code is Netbeans-generated and most of it not editable.
    Many thanks in advance.
    George

    Once again you are right my friend. I jumped to conclusion way too fast, when I shouldn't. (Give me a break, I've been busting my head with this well over a week). The response I saw when I did that was that indeed a line is added to the jTable. Because I falsly set the index of the object to be added to be second to last the row appeared on the table, what I didn't see at the time was that the last one disappeared. Hmm...
    A new adventure begins...
    So after a few hours of messing around with it here are my observations:
    1) It was not an observable list. When I add the new element with employeesList.add(newEmp); , the table gets notified but a get a bunch of exceptions:
    xception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 84, Size: 84
            at java.util.ArrayList.RangeCheck(ArrayList.java:546)
            at java.util.ArrayList.get(ArrayList.java:321)
            at org.jdesktop.swingbinding.impl.ListBindingManager$ColumnDescriptionManager.validateBinding(ListBindingManager.java:191)
            at org.jdesktop.swingbinding.impl.ListBindingManager.valueAt(ListBindingManager.java:99)
            at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.getValueAt(JTableBinding.java:713)
            at javax.swing.JTable.getValueAt(JTable.java:1903)
            at javax.swing.JTable.prepareRenderer(JTable.java:3911)
            at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
            at javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1974)
            at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:1897)
            at javax.swing.plaf.ComponentUI.update(ComponentUI.java:154)
            at javax.swing.JComponent.paintComponent(JComponent.java:743)
            at javax.swing.JComponent.paint(JComponent.java:1006)
            at javax.swing.JViewport.blitDoubleBuffered(JViewport.java:1602)
            at javax.swing.JViewport.windowBlitPaint(JViewport.java:1568)
            at javax.swing.JViewport.setViewPosition(JViewport.java:1098)
            at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(BasicScrollPaneUI.java:818)
            at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(BasicScrollPaneUI.java:807)
            at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel.java:348)
            at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeModel.java:285)
            at javax.swing.DefaultBoundedRangeModel.setValue(DefaultBoundedRangeModel.java:151)
            at javax.swing.JScrollBar.setValue(JScrollBar.java:441)
            at javax.swing.plaf.basic.BasicScrollBarUI.scrollByUnits(BasicScrollBarUI.java:907)
            at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.mouseWheelMoved(BasicScrollPaneUI.java:778)
            at javax.swing.plaf.basic.BasicScrollPaneUI$MouseWheelHandler.mouseWheelMoved(BasicScrollPaneUI.java:449)
            at apple.laf.CUIAquaScrollPane$XYMouseWheelHandler.mouseWheelMoved(CUIAquaScrollPane.java:38)
            at java.awt.Component.processMouseWheelEvent(Component.java:5690)
            at java.awt.Component.processEvent(Component.java:5374)
            at java.awt.Container.processEvent(Container.java:2010)
            at java.awt.Component.dispatchEventImpl(Component.java:4068)
            at java.awt.Container.dispatchEventImpl(Container.java:2068)
            at java.awt.Component.dispatchMouseWheelToAncestor(Component.java:4211)
            at java.awt.Component.dispatchEventImpl(Component.java:3955)
            at java.awt.Container.dispatchEventImpl(Container.java:2068)
            at java.awt.Component.dispatchEvent(Component.java:3903)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4256)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3866)
            at java.awt.Container.dispatchEventImpl(Container.java:2054)
            at java.awt.Window.dispatchEventImpl(Window.java:1801)
            at java.awt.Component.dispatchEvent(Component.java:3903)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 84, Size: 84
            at java.util.ArrayList.RangeCheck(ArrayList.java:546)
            at java.util.ArrayList.get(ArrayList.java:321)
            at org.jdesktop.swingbinding.impl.ListBindingManager$ColumnDescriptionManager.validateBinding(ListBindingManager.java:191)
            at org.jdesktop.swingbinding.impl.ListBindingManager.valueAt(ListBindingManager.java:99)
            at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.getValueAt(JTableBinding.java:713)
            at javax.swing.JTable.getValueAt(JTable.java:1903)
            at javax.swing.JTable.prepareRenderer(JTable.java:3911)
            at javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:2072)
    ... and a lot morewhich from my poor understanding means that the jTable succesfully notices the change but it is not able (??) to adjust to the new change. What is more interesting is that when I plainly add the element to the end of the list (without an idex that is), a blank row appears at the end of my Table. The weird thing is that I've bound the table to some text fields below it, and when I select that empty row all the data appear correctly to the text fields.
    I tried going through:
                    org.jdesktop.observablecollections.ObservableCollections.observableList(employeesList).add(newEmp);as well as
                    help = org.jdesktop.observablecollections.ObservableCollections.observableListHelper(employeesList);
                    help.getObservableList().add(newEmp);
                    help.fireElementChanged(employeesList.lastIndexOf(newEmp));and
                    obsemployeesList = org.jdesktop.observablecollections.ObservableCollections.observableList(employeesList);
                    obsemployeesList.add(newEmp);and I still get the same results (both the exeptions and the mysterious empty row at the end of the table
    So, I'm again in terrible need of your advice. I can't thank you enough for the effort you put into this.
    Best regards,
    George
    Edited by: tougeo on May 30, 2009 11:06 AM
    Edited by: tougeo on May 30, 2009 11:21 AM
    Edited by: tougeo on May 30, 2009 11:30 AM

  • How can i use the highlight row to select the row on a report

    The row is highlighted as I move the mouse how can I select this row without having to make a column a text link.
    thanks in advance

    Hi
    Try this out.
    Create or alter a report template. In the 'Before Each Row' section paste:
    <tr onMouseOver="cOn(this);" onMouseOut="cOut(this);">
    In the 'After Each Row' section paste:
    </tr>
    In the report page definition click on the page attributes and navigate to the HTML Header section. Paste the following script into this section:
    </script>
    <script language="JavaScript1.2">
    function cOn(td){
    if(document.getElementById||(document.all && !(document.getElementById))){
    td.style.backgroundColor="#cccccc";
    function cOut(td){
    if(document.getElementById||(document.all && !(document.getElementById))){
    td.style.backgroundColor="#ffffff";
    </script>
    In the report region navigate to the 'Layout and Pagination' section and select the report template you altered above.
    Now the report row will get highlighted when you mouse over. If you want to change colors, edit the color attributes in the javascript.
    Regards
    Kiran Akkiraju

  • There was a row nad now the row is no longer in the standard report

    Hi All
    we have one Webi report which display Earned Value Financial report.
    Recently user complaints that one of the row has been disappear in the report.
    I just had a look and i couldn't find how this has been disappeared? is it possible to add it again?
    I am new to BO. so can any one help me on this?
    Thanks

    Hi,
    Copy the report SQL and run on the database.and see number of records are same or not.
    check the same record is exist in the database on same conditions.
    Thanks,
    Amit

  • Add dynamic buttons to each report row and bind the row data to buttons specific to that row

    I have a page with a form at the top and a report at the bottom which is tied to a table. I need to add a pair of buttons for each row of the table and add dynamic actions for these buttons. I need to submit the data corresponding to the row to a REST service and refresh the table/row. I know it is possible to add ajax call and refresh the table after the response is received. But I am not sure how I can dynamically include a pair of buttons on each row and have the access the data corresponding to the record when a particular button is clicked. I was not able to find such a feature using the help page. Can you please let me know if this is possible. Thanks in advance.
    Below is the representation of how I need the page to look like.
    Col 1
    Col 2
    Col 3
    data 1
    data 21
    data 31
    Button 1
    Button 2
    data 2
    data 22
    data 32
    Button 1
    Button 2
    data 3
    data 23
    data 33
    Button 1
    Button 2
    data 4
    data 24
    data 34
    Button 1
    Button 2
    I should be able to access data 1, data21, data 31 from button 11 and button21 etc.

    select data1,
              data2,
              data3,
              null button1,
              null button2,
              rowid r_id
    from .....
    If you edit the column for button1 and navigate to the Column Formatting region you can create your button here, several different ways.  You will need to play around with how you prefer.  See below:
    <input class="button1" type="button" id="#R_ID#" value="label for the button" /> or <button id="#R_ID#">label for button</button> or you could use <a> and apply css of your theme.
    You also create both buttons in a single column.  From here you can reference any of the columns from your select by using the #COLUNMNAME# format (as I did with R_ID).
    You will next need to something similar for all columns you want to be able to grab when you click the buttons.  See below:
    --- This would be for data1 column
    <span id="D1-#R_ID#">#DATA1#</span>
    You would do these for each column that you want access to when button clicked as mentioned above.  You could bypass this step and use jquery to traverse the DOM using .closest() and .find() and give each column a distinct class.  Is is your preference.
    You would then create a dynamic action triggered when .button1 is clicked.  Now that you have that object you can get the id of the triggering object which would be your r_id and from there you can access all your individual data points(all this done in a javascript in the dynamic action) and assign to hidden items on your page.  The next step of that dynamic action you could execute pl/sql and pass those in page items.
    Hope that all makes sense.
    David
    Message was edited by: DLittle
    Just as a bit of clarification:  the r_id column does not have to be rowid, but it does need to be unique for each row return.  You could use your primary key or rownum.  Whatever works for your scenario.

Maybe you are looking for