CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2002
    Location
    paris
    Posts
    2

    URGENT JTable : deselect a cell at runtime

    Hi,

    I need to deselect a cell at runtime (by clicking on a JButton) in a JTable and I can't managed to do it with isCellEditable()...

    Does anybody have any idea how to do it ??
    please help,
    Thanks a lot by advance.

    Hélène.

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    I don't know of a simple way to deselect a single cell programmatically. As far as I know, you can only deselect whole rows and columns.

    What you can do is fake it by using a TableCellRenderer that treats the cell in question as unselected and without focus, something like this:
    Code:
    table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
    	public Component getTableCellRendererComponent (JTable table,
                                Object value,
                                boolean isSelected,
                                boolean hasFocus,
                                int row,
                                 int column)
    	{   
    		// Use appropriate row & col values here
    		if (row == 2 && column == 2) {
    			isSelected = false;
    			hasFocus = false;
    		}
    		return super.getTableCellRendererComponent(table,
    			value, isSelected, hasFocus, row, column);
    			                         	
    	}                                 
    });
    Then you can ensure it won't be edited with isCellEditable().
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured