Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3741
  • Last Modified:

Do not Edit Jtable cell

hello there,

i have a JTable and in it i have this method which does not allow cells to be edited.isCellEditable(int row, int column).
but my problem is when i double clcik on a cell i can write inside those cell.i want to even prevent this to happen.i need something like the JTextfield which has this setFocusable(false);

cheers
zolf
0
zolf
Asked:
zolf
  • 3
  • 3
  • 3
2 Solutions
 
objectsCommented:
if isCellEditable is returning false then the cell should not be editable
0
 
zolfAuthor Commented:

yes it is not editing but i dont want it to allow users to type anything in the cells
0
 
objectsCommented:
if its not edittable then they cannot type anything in the cell
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
zolfAuthor Commented:

this is my code.
public void tableChanged(TableModelEvent tme)
    {
             int row = table.getEditingRow();
         int column = table.getEditingColumn();
         //System.out.println("table changed...."+ row +"  "+column);
            if(isCellEditable(row,column))
            {                  
                  //System.out.println("Can edit");
                  printDebugData(table, row, column);
            }
            else
            {
                  //System.out.println("Cannot edit");
            }
    }
   
      public boolean isCellEditable(int row, int column)
      {
            boolean value = false;
            
          if (column == 1)
          {
            value = false;
          }
          else if(column == 0 || column == 2 || column == 3 || column == 4)
          {
                value = false;
          }
          return value;
       }
0
 
CEHJCommented:
You need to override isCellEditable in your TableModel
0
 
zolfAuthor Commented:


what do you mean.this is how i define my jtable

model = new DefaultTableModel(data, columnNames);
            
            table = new JTable(model);

give me me example to what you meant
0
 
objectsCommented:
where is the code u are using above?
By the looks it is not being called.
The isCellEditable methods needs to be a part or your JTable or your TabelModel to work.
0
 
CEHJCommented:
Should be

model = new DefaultTableModel(data, columnNames) {
    public boolean isCellEditable(int row, int col) {
        return col != 0; // Don't allow first col to be edited
    }
};
0
 
CEHJCommented:
:-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now