Results 1 to 6 of 6

Thread: Editing JTable cells

  1. #1
    Join Date
    Mar 2010
    Posts
    338

    Editing JTable cells

    Hello,
    I program in Java 1.6. I wonder if it is possible to specify the cells editable and uneditable a JTable. By default, all cells are editable. Is it possible to say that some cells may not be edited? Thank you

  2. #2
    Join Date
    Nov 2009
    Posts
    359

    Re: Editing JTable cells

    It will create a custom TableModel, where you override the function isCellEdiatble ();
    Code:
    MyTableModel public class extends ( Override public DefaultTableModel isCellEditable boolean (int rowIndex, int columnIndex) (/ / here the cell (1, 2) is non-editable if (rowIndex == 1 & & columnIndex == 2) return false; / / the rest is editable return true;))
    If you want an entire column is not editable you test only on the index of the column:
    Code:
    if (columnIndex == 5) return false; / / in column 5 is not editable.

  3. #3
    Join Date
    Nov 2009
    Posts
    330

    Re: Editing JTable cells

    Even easier if you do not want to create an additional class for various reasons:

    Code:
    JTable tb = new JTable (ls, cls) ( 
    
    public boolean isCellEditable (int r, int c) ( 
    
    return false; 
    
    ) 
    
    )

  4. #4
    Join Date
    Sep 2009
    Posts
    152

    Re: Editing JTable cells

    Have a rendered with a self-written SpinBox it. This renderer is now in every cell of my spreadsheet with this SpinBox (you can set values from 0-99) appears. Now I want but also the Value (ie the adjusted value) of the query spinBox and as I have still problems. Actually, I better each cell to the value of SpinBox ask?

  5. #5
    Join Date
    Dec 2009
    Posts
    211

    Re: Editing JTable cells

    I somehow understand the problem completely. If your <br> self-made SpinBox (BTW it from JDK1.4 as a swing-<br> Component exists), as cell renderers and used as CellEditor <br> is, it needs to implement even the CellEditor interface, <br> eg from javax.swing.AbstractCellEditor (JDK1.3 be derived). <br>
    Somewhere in this derived class, that is in your Custom <br>
    Editor, it would have something like
    Code:
    GetCellEditorValue Object (); and 
    setCellEditorValue (Object o)
    </ Code> type.

  6. #6
    Join Date
    Dec 2009
    Posts
    292

    Re: Editing JTable cells

    The last method is of
    Code:
     <code> stopCellEditing () <call / code>, <br>
    and queries the value of your spinBox, eg <br>
    <code>
    public boolean stopCellEditing () (
    SpinBox spinBox renderer.getSpinBox = (); / / get editing component
    setCellEditorValue (new Integer (spinBox.getValue ()));
    super.stopCellEditing return (); / / fire change event to listeners
    )
    </ Code>
    Thus, the value of the set for the edited SpinBox <br>
    Cell, interrogated and sent to JTable.
    <p>

Similar Threads

  1. What is the use of JTable class?
    By Khan Baba in forum Software Development
    Replies: 5
    Last Post: 13-02-2010, 11:41 AM
  2. Fill JTable with several values
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 19-01-2010, 02:39 PM
  3. Print JTable with the help of java
    By Coldman in forum Software Development
    Replies: 3
    Last Post: 25-11-2009, 09:02 AM
  4. How to retrieve data from a jTable in Java and MS access
    By Corona in forum Software Development
    Replies: 3
    Last Post: 09-07-2009, 11:59 AM
  5. How to refresh data of Jtable in java
    By sarmad_iu in forum Software Development
    Replies: 1
    Last Post: 28-05-2009, 02:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,669,542.45672 seconds with 17 queries