Making a jtable row noneditable based on a value in a certain cell.

I have a jTable (based on a database table) and one of the columns is OWNER. Is there a way to make an entire row noneditable based on the value in the OWNER column of the currently selected row?
Here is the listener code that I have on the jTable. I want to be able to make the entire row noneditable if the value (of the currently selected row) of the OWNER column is "SYSTEM". If it is anything other than "SYSTEM" then the user would be able to change the values on the row.
I can't override the isCellEditable method, because I only want the rows with the value of "SYSTEM" in the OWNER column to be noneditable.
jTable2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel rowSM = jTable2.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) return;
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
//no rows are selected
} else {
int selectedRow = lsm.getMinSelectionIndex();
if (jTable2.getValueAt(selectedRow, 1).equals("SYSTEM"))
System.out.println("Selected Row: " + selectedRow);
System.out.println("Owner Value: " + jTable2.getValueAt(selectedRow, 1));
//Make all cells in this row non-updateable???
//Need code to make the currently selected row noneditable
disableRetailerAddToList();
} else
enableRetailerAddToList();
Any direction for this problem would be greatly appreciated.

I've resolved it with some help by using the following:
NOT ([<plCall_Back_Required_ITAG>]=LookupValue("OCC_CUST_LOV_SR_3", "Yes") AND [<stCall_Back_Number_ITAG>] IS NULL)

Similar Messages

  • Change the row colors based on column values in MOSS 2007.

    Hi Team,
    I am using MOSS 2007 environment. In that I am having one SharePoint list. In that list based on column values rows colors need to change.
    Kindly help me anyone on this.
    Thanks,
    Ashok

    Hi Ashok,
    Please follow the below link:
    http://www.contentmaster.com/sharepoint-2010/conditional-formatting-of-list-views-for-sharepoint-2010-changing-the-font-colour/
    http://sharepoint.stackexchange.com/questions/7478/highlight-row-color-based-on-field-values-in-sharepoint-2010-list-view
    Best Regards,
    Brij K

  • Sort jTable rows by column as Integer value

    Hi all,
    I have problem with sort jTable rows. I have some columns and in first are integer data. jTable sort that as String value..1,10,11,12....2,21, ...
    How can I do that?
    Thanks

    In the future, please post Swing questions to the Swing forum: http://forum.java.sun.com/forum.jspa?forumID=57
    What does the TableModel's getColumnClass method return for that column?

  • Dynamic table rows created based on input value

    I've been searching the forum for either a tutorial or input
    on how to create a table where the number of rows are based on a
    user input value. I can't seem to find anything on this.
    Here's what I'm trying to do. I have site where people are
    charged based on the number of items they register. So if they want
    to register 2 items. They would input the number 2 for quanity and
    I would display a dynamic table with 2 rows. The user will input
    their data for the 2 items and I insert this into an
    itemsRegistered table. If they entered 4 I would give them 4 rows
    for input. I am using dreamweaver with PHP and MySql database. Can
    anyone point me in the right direction. Any help would be
    appreciated!

    Not exactly. The items are all the same but have a different
    registration number (like a serial number). So if the user wants to
    register 2 items. They would input the number 2 on the form. Then 2
    rows would appear on the table, one for each registration number.
    When they finish entering the data it would be inserted into the
    database as 2 records.
    So for example if item 1 has registration number 10000 and
    item 2 has registration number 11000. The registration numbers are
    unique. The table would look like this :
    CustomerID (links to customer table)
    RegistrationID (Unique in this table)
    ItemColor
    ItemShape
    I don't know if I've explained this well but thanks for even
    attempting to answer this! I really appreciate it!

  • How can I do a multi-row insert based on a value in a field on my form?

    My Form contains these fields (for the purpose of inserting rows into my 'Ports' table)
    ..Number_of_Ports
    ..Device_Name
    ..Router_Name
    ..Router_Slot_Number
    ..Router_Port_Number
    ..Vlan_Number
    Based on the value entered for 'Number_of_Ports'
    I would like to insert 'X' number of rows into my 'Ports' Table
    with the values which are contained in:
    ..Device_Name
    ..Router_Name
    ..Router_Slot_Number
    ..Router_Port_Number
    ..Vlan_Number
    Can someone help me with this,
    Or should I post this on another forum?
    Thanks in advance- Gary

    Gary,
    You can accomplish this with a PL/SQL process using a FOR LOOP. For the following example, I am going to use fields that would have been generated for Page 1 of an application:
    Begin
    FOR i IN 1..:P1_NUMBER_OF_PORTS LOOP
    INSERT INTO tablename(port_number, device_name, router_name, router_slot_number_vlan_number)
    VALUES(i, :P1_DEVICE_NAME, :P1_ROUTER_NAME, :P1_ROUTER_SLOT_NUMBER, :P1_ROUTER_PORT_NUMBER, :P1_VLAN_NUMBER);
    End Loop;
    End;
    Hope this helps.
    Mike

  • JTable row color based on a certain value

    Can anyone please show some code on how
    I can change the background color of an entire
    row based on a string value from the first column ?
    Every time that the first column contains the
    string "TOTAL", I want the entire row to have
    another background color.
    Thanks a lot

    Override getTableCellRendererComponent in Table celll renderer.
    public class MyTableCellRenderer extends DefaultTableCellRenderer
    public MyTableCellRenderer()
    super();
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column)
    Component comp = super.getTableCellRendererComponent(table, value, isSelected,
    hasFocus, row, column);
              ((JLabel)comp).setOpaque(true);
    if(value.equals("TOTAL")
    comp.setBackGround(color);
    else
    set whatever the default background color

  • Conditional formatting of a cell based on a value in another cell

    I want to change the color of the text in a cell based on the value in a different cell. How can I accomplish this?

    drmjdoyle,
    There Numbers User Guide, http://support.apple.com/en_US/manuals/#iwork, will show you how to do that. Also, doing a search in these forums will provide many hits answering your question.
    Click in the cell you want the color to change: click Format > Create custom cell format, in the first dropdown in that dialog box click Choose Rule, then follow the prompts.
    Cordially,
    RicD

  • Making JTable rows not editable

    i need to make a jtables rows and columns to not be editable, but i also need it to be able to be selectable. i know one way to do it is to extend defaulttablemodel and overwrite the iscelleditable method, but the problem is that i'm already extending jframe. is there any other way to do this keeping jframe extended, because i need it to be extended?
    thanks for the help

    JTable table = new JTable(..){
      public boolean isCellEditable(int row, int column){
        return false;
    };

  • Coloring JTable rows depending on the actual and previous value

    I need to change the background of the entire row of a JTable, but with the condintion of checking the value (Integer) in the column 0 of each row.
    I the actual value is equal to previous value I keep the same color (any color) if it is different I must change the color (to any other color).
    Any ideas how I could do that? I suppose I cant use CellRenderer because the Table is already full, so I was thinking about making a looping thru the table and chaning the background colors, but I have no idea how to do that.
    So far I have this code:
    int totalRows = modProdutos.getRowCount();
    int totalCols = modProdutos.getColumnCount();
    System.out.println("Total rows: " + totalRows);
    TableColumnModel tcm = tbProdutos.getColumnModel();
    DefaultTableModel modelo = (DefaultTableModel) tbProdutos.getModel();
    if (totalRows > 0) {
        int numeroOSAntes = (Integer) tbProdutos.getValueAt(0, 0);
        for (int i = 0; i < totalRows; i++) {
            int numeroOS = (Integer) tbProdutos.getValueAt(i, 0);
            if (numeroOS == numeroOSAntes) {
                // Paint the background with the same color (any color)
                System.out.println("Same Color: " + numeroOSAntes + " - " + numeroOS);
            } else {
                // Paint the background with a different color (any other color)
                System.out.println("Different color: " + numeroOSAntes + " - " + numeroOS);
            // keep the previous control number
            numeroOSAntes = numeroOS;
    }

            jTable1 = new JTable(0,4){
                @Override
                public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
                    Component c = super.prepareRenderer(renderer, row, column);
                    c.setBackground(Color.YELLOW);
                    boolean yellow = true;
                    for (int i = 1; i <= row; i++) {
                        if(!getValueAt(i,0).toString().equals(getValueAt(i-1,0).toString())){
                            yellow = !yellow;
                    if(!yellow){
                        c.setBackground(Color.WHITE);
                    return c;
            model = (DefaultTableModel)jTable1.getModel();
            model.addTableModelListener(new TableModelListener() {
                public void tableChanged(TableModelEvent e) {
                    jTable1.repaint();
            });

  • Changing JTable Row Color OnMouseOver

    Hello everybody,
    is it possible to change JTable Row Color when Mouse passes over it ??
    THanks!

    Yes...
    You have to override the table cell renderer and set the color of the rows based on flag.
    The flag can be turned on/off in a mouse motion listener of the table.

  • Report row highlight based on a page item

    Is there a way to highlight a report row based on the value of a page item?
    In my case I have a report where the application user requests data in a detail report using a column link in the master report. This loads an id number from my report into a page item (say :P8_ID for example). If this item is null, I want the report rows to all render normally (nothing is selected or the detail report has been closed). If there is an id in that field then I want the row containing the information about that item to highlight (its column link has been clicked selected it to bring up a detail report).
    At first glance, this looks similar to Vikas solution (Change the Report row color when clicked but I am trying to make the connection between what has already been done and where I need to be.

    After looking back, I discovered my value was being set after the report rendered. When I re-organized my calculations and the rest, it worked.

  • Add JTable Row Headers At The End Of The Rows(At Right)?

    hi all
    i got this example for adding JTable Row Headers,but it adds the headers at the left(beginning of the row)
    and i want to add the headers at the end of the row(at right),any ideas how to do that?
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.AbstractListModel;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.ListCellRenderer;
    import javax.swing.ListModel;
    import javax.swing.UIManager;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    * @version 1.0 11/09/98
    class RowHeaderRenderer extends JLabel implements ListCellRenderer {
      RowHeaderRenderer(JTable table) {
        JTableHeader header = table.getTableHeader();
        setOpaque(true);
        setBorder(UIManager.getBorder("TableHeader.cellBorder"));
        setHorizontalAlignment(CENTER);
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        setFont(header.getFont());
      public Component getListCellRendererComponent(JList list, Object value,
          int index, boolean isSelected, boolean cellHasFocus) {
        setText((value == null) ? "" : value.toString());
        return this;
    class RowHeaderExample extends JFrame {
      public RowHeaderExample() {
        super("Row Header Example");
        setSize(370, 150);
        ListModel lm = new AbstractListModel() {
          String headers[] = { "Row1", "Row2", "Row3", "Row4"};
          public int getSize() {
            return headers.length;
          public Object getElementAt(int index) {
            return headers[index];
        DefaultTableModel dm = new DefaultTableModel(lm.getSize(), 4);
        JTable table = new JTable(dm);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setRowHeight(18);
        JList rowHeader = new JList(lm);
        rowHeader.setFixedCellWidth(50);
        rowHeader.setFixedCellHeight(18);
        rowHeader.setCellRenderer(new RowHeaderRenderer(table));
        JScrollPane scroll = new JScrollPane(table);
        scroll.setRowHeaderView(rowHeader);
        getContentPane().add(scroll, BorderLayout.CENTER);
      public static void main(String[] args) {
        RowHeaderExample frame = new RowHeaderExample();
        frame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
        frame.setVisible(true);
    }

    fixed by:
    list.setBackground(table.getTableHeader().getBackground());here's the full code:
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.ComponentOrientation;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.DefaultListModel;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.ListCellRenderer;
    import javax.swing.UIManager;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.JTableHeader;
    * @version 1.0 11/09/98
    class RowHeaderRenderer extends JLabel implements ListCellRenderer {
      JTable table;
      RowHeaderRenderer(JTable table) {
        this.table = table;
        JTableHeader header = table.getTableHeader();
        setOpaque(true);
        setBorder(UIManager.getBorder("TableHeader.cellBorder"));
        setHorizontalAlignment(CENTER);
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        setFont(header.getFont());
      public Component getListCellRendererComponent(JList list, Object value,
          int index, boolean isSelected, boolean cellHasFocus) {
        list.setBackground(table.getTableHeader().getBackground());
        setText((value == null) ? "" : value.toString());
        return this;
    class RowHeaderExample extends JFrame {
      public RowHeaderExample() {
        super("Row Header Example");
        setSize(370, 150);
        setLocationRelativeTo(null);
        DefaultListModel lstModel = new DefaultListModel();
        lstModel.addElement("Row 1");
        lstModel.addElement("Row 2");
        lstModel.addElement("Row 3");
        lstModel.addElement("Row 4");
        DefaultTableModel dm = new DefaultTableModel(lstModel.getSize(), 4);
        JTable table = new JTable(dm);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setRowHeight(18);
        JList rowHeader = new JList(lstModel);
        rowHeader.setFixedCellWidth(50);
        rowHeader.setFixedCellHeight(18);
        rowHeader.setCellRenderer(new RowHeaderRenderer(table));
        JScrollPane scroll = new JScrollPane(table);
        scroll.setRowHeaderView(rowHeader);
        table.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        scroll.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        getContentPane().add(scroll, BorderLayout.CENTER);
      public static void main(String[] args) {
        RowHeaderExample frame = new RowHeaderExample();
        frame.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
        frame.setVisible(true);
    }

  • Count the number of rows based on the values!!!

    Hi all,
    What I am using:
    I am working with a multidimensional database in Visual Studio 2010 using its Data source view and calculation member and dimension usage.
    What I want to do:
    I have a fact table that has five columns(leg(s),hand(s), Head and body,overall) that shows the category of how severe the injury is. Let say for the records all columns never have an empty value(no injury is stated with 'No injury' ) . These five columns
    are connected with a dimension that has all the available values (Category A-E of injury).The overall has the most severe from the other four columns. I want to create a bar chart with five different measure
    values, one for each column, and count the values in those columns. 
    For example : I have a slicer in the excel and a bar chart and the slicer has all the values of the Category of the injury ( Cat a,Cat B, Cat C, ... Cat E, No injury ) and when i select one of them, lets say
    Cat C,  the bar chart should update and show how many Cat C each measurement column has. 
    Example FACT table:
    ID      LEG      HAND    HEAD   BODY OVERALL
    1        No         A           No        No        A
    2        No        D            C          C         C
    3    E         C            D           A         A
    4         E          E           B            C         B
    So if i selected C the bar chart will count   (Leg = 0, Hand = 1, Head = 1, body = 2 and Overall = 1).
    Any ideas ?
    Thanks for the help and the time :) 

    Hi DBtheoN,
    According to your description, you want to create a chart on excel worksheet to count the rows based on the value, right? If in this case, I am afraid this issue is related to Office forum, I am not the expert of Office, you can post the issue on the corresponding
    forum.
    However, this requirement can be done easily on SQL Server Reporting Services. You can using the expression below to count the rows.
    =COUNT(IIF(Fields!LEG.Value=Parameters!TYPE.Value,1,NOTHING))
    Regards,
    Charlie Liao
    TechNet Community Support

  • Double click on a JTable row.

    I got and run a sample about double click on a JTable and it works fine. This sample defines a TableModel as shown at the end this note.
    On the other hand, I have an application in which I have defined a JTable
    using the DefaultTableModel as follows :
    DefaultTableModel dtm = new DefaultTableModel(data, names);
    JTable table  = new JTable(dtm);  where data and names are String arrays.
    Of course the mouse listener stuffs have been also specified.
    table.addMouseListener(new MouseAdapter(){
         public void mouseClicked(MouseEvent e){
          if (e.getClickCount() == 2){
             System.out.println(" double click" );
         } );Because the difference with the sample was the table model,
    I changed it with the DefaultTableModel class. At this point, the Double click does not work anymore.
    So I gues it should be an option which prevents double click to work.
    I thought of using mousePress() instead of mouseClick(), but it's very dangerous (I tried). . If by error the user clicks twice (instead of only once) the mousePress method is invoked twice for the same entry
    My question is now simple, may I use double click on a JTable with the default table model. If so, what I have to do ?
    Thanks a lot
    Gege
    TableModel dataModel = new AbstractTableModel() {
         public int getColumnCount() { return names.length; }
         public int getRowCount() { return data.length;}
         public Object getValueAt(int row, int col) {return data[row][col];}
         public String getColumnName(int column) {return names[column];}
         public Class getColumnClass(int col) {return getValueAt(0,col).getClass();}
         public void setValueAt(Object aValue, int row, int column) {
           data[row][column] = aValue;
         };

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class ClickIt extends MouseAdapter
        public void mousePressed(MouseEvent e)
            JTable table = (JTable)e.getSource();
            Point p = e.getPoint();
            if(e.getClickCount() == 2)
                System.out.println("table.isEditing = " + table.isEditing());
            int row = table.rowAtPoint(p);
            int col = table.columnAtPoint(p);
            String value = (String)table.getValueAt(row,col);
            System.out.println(value);
        private JTable getLeftTable()
            final String[] names = { "column 1", "column 2", "column 3", "column 4" };
            final Object[][] data = getData("left");
            TableModel dataModel = new AbstractTableModel() {
                public int getColumnCount() { return names.length; }
                public int getRowCount() { return data.length;}
                public Object getValueAt(int row, int col) {return data[row][col];}
                public String getColumnName(int column) {return names[column];}
                public Class getColumnClass(int col) {return getValueAt(0,col).getClass();}
                public void setValueAt(Object aValue, int row, int column) {
                    data[row][column] = aValue;
            JTable table = new JTable(dataModel);
            return configure(table);
        private JTable getRightTable()
            String[] colNames = { "column 1", "column 2", "column 3", "column 4" };
            JTable table = new JTable(new DefaultTableModel(getData("right"), colNames));
            return configure(table);
        private Object[][] getData(String s)
            int rows = 4, cols = 4;
            Object[][] data = new Object[rows][cols];
            for(int row = 0; row < rows; row++)
                for(int col = 0; col < cols; col++)
                    data[row][col] = s + " " + (row*cols + col + 1);
            return data;
        private JTable configure(JTable table)
            table.setColumnSelectionAllowed(true);
            table.setCellSelectionEnabled(true);
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            table.setPreferredScrollableViewportSize(table.getPreferredSize());
            table.addMouseListener(this);
            return table;
        private JPanel getContent()
            JPanel panel = new JPanel(new GridLayout(1,0,0,5));
            panel.add(new JScrollPane(getLeftTable()));
            panel.add(new JScrollPane(getRightTable()));
            return panel;
        public static void main(String[] args)
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(new ClickIt().getContent());
            f.pack();
            f.setVisible(true);
    }

  • Color report rows based on a value in that row

    I would like to Color report rows based on a value in that row.
    For examplle with the "EMP" table:
    I would like job=MANAGER to be red and job=CLERK to be green etc etc
    The other example I found only had the option of one color either the highlight or the default color.
    I am looking for a way to do multiple colors.

    Hi,
    In the row template, you can use #1#, #2#, etc to indicate where a field in the report needs to be output. This does not have to be plain text - ie, you can use it within style tags if you like.
    So, take a query like:
    SELECT EMPNO,
    ENAME,
    DEPTNO,
    DECODE(DEPTNO, 10, 'green', 20, 'red', 30, 'cyan', 'white') BG_COLOUR
    FROM EMPYou get columns 1=empno, 2=ename, 3=deptno and 4=bg_colour. In the row template, you can then do:
    Before Rows setting (sets up the table):
    &lt;table&gt;
    &lt;tr&gt;&lt;td&gt;ID&lt;/td&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Dept&lt;/td&gt;&lt;/tr&gt;After Rows setting (closes the table):
    &lt;/table&gt;Row Template 1 (used for ALL rows):
    &lt;tr style="background-color:#4#;"&gt;&lt;td&gt;#1#&lt;/td&gt;&lt;td&gt;#2#&lt;/td&gt;&lt;td&gt;#3#&lt;/td&gt;&lt;/tr&gt;Then, for every row, the colour that has been calculated using the DECODE function will be used in the style tag to colour the background for the entire row.
    How you determine the colours is up to you. I've used DECODE here, but you could use a field on the DEPT table to hold this and use this in your SQL statement.
    Andy

Maybe you are looking for

  • Need to print the company logo in alv report

    Hi All ,        I am displaying an alv grid for some QM report .        I have used top-of-page event and   'REUSE_ALV_COMMENTARY_WRITE '    FM to display the logo and header . Every thing is working fine .   But when I am taking the print-out  the l

  • Problems with migrating btmail to IMAP in outlook...

    After migrating from pop to IMAP succesfully, today, after only one day, my incoming emails are not working anymore in outlook 2011.   I regularly receive and send emails from my other devices, ie iphone and ipad, but Outlook 2011 tells me " not conn

  • Nothing on the screen

    new IMAC 24; problems from out of the box; in shop twice already; put IMAC to sleep last night; this morning, wake it up; receive log in screen, then black; no images; no desktop view; pressing f 9 give me the dashboard; use mouse to select a program

  • Order by in SQL Server

    I have data in table as below.My requirement is -->result should come in descending menu order i.e highest menu order should come first and if two records have same Menu order then the highest LastUpdatedDateTime   in those 2 records should come firs

  • 'SESSION_MANAGER' error in ecatt

    Hi , I am trying to record a transaction in SAPGUI mode ,then I select 'pattern' then 'SAPGUI record' then give the granuality then when I press the 'start recording' button I am getting the following message Error in target system: User does not hav