How to set JTable cells to uneditable

I was trying to set the cells in my Jtable to uneditable.
I overrided the isCellEditable method. Here is what I did. But the
cells remain editable. Any ideas?
private class MyTableModel extends DefaultTableModel
public MyTableModel(Vector vectRow,Vector vecColumn)
super(vecVector,vecColumn);
public boolean isCellEditable(int row, int col)
if (col >= 0) {
return false;
}

Just Use:
public boolean isCellEditable(int r, int c) { return false; }

Similar Messages

  • How to set JTable cell editable/non-editable dynamically using NetBean?

    I am using NetBean 6.5, create a database desktop application, I using the persistence entity manager to bind my JTable with database.
    Now, I want to set practicular cells which are enable and disable, I tried to create my own table model and override the isEditable() method, which it seems didn't work. I guessed the problem is the persistence connection between my Table and database.
    How can I solve it? Any example? I just googled the web and can't find example which use netbean combined with database. I know that a single JTable would work when creating your own model.
    thx.

    I know what coding i did, Yes u r right but im new to GUI programming only,
    That's why i posted it to forums, I gone through the Control Flow Statements link what u have given.
    U didnt get my question at all.
    Again the problem im facing is the table is already displayed with 2nd column uneditable.
    When some Action done on table, i need to make 2nd column editable at run time.
    Thanks if u provide me the solution instead of deciding what type of programmer im.

  • How to set jtable editable?

    how to set jtable editable?

    Hi,
    Doubleclick on a particular cell to get the cellEditor for editing.
    Cheers :)
    Nagaraj

  • How to set table cell renderer in a specific cell?

    how to set table cell renderer in a specific cell?
    i want set a cell to be a button in renderer!
    how to do?
    any link or document can read>?
    thx!

    Take a look at :
    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    It is very interesting, and I think your answer is here.
    Denis

  • Setting JTable cell editor

    Hallo,
    I have troubles setting jtable cell edtior. when i run code below, editor stays unchnaged.
    Do you know where's the problem, please (except in programmer^_^) ???
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    public class Test extends JFrame {
        JTable table;
        Test() {
            // Create table model
            table = new JTable();
            table.setModel(new DefaultTableModel(
                new Object[][] {
                    { Boolean.TRUE, Integer.valueOf(10) },
                    { "Hallo!", Boolean.FALSE },
                }, new String[] { "Col1", "Col2" }));
            // Setup frame a little
            setLayout(new BorderLayout());
            setBounds(new Rectangle(300,300,200,100));
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            add(table,BorderLayout.CENTER);
             * Two calls below have no effect:-(
             * What did i wrong?
            // set cell editor for all cells
            table.setCellEditor(new DefaultCellEditor(
                    new JComboBox(new String[] { "0", "1" }) ));
            // Use checkbox for booleans
            table.setDefaultEditor(Boolean.class, new DefaultCellEditor(
                    new JCheckBox() ));
            // Use combobox for strings
            table.setDefaultEditor(String.class, new DefaultCellEditor(
                    new JComboBox( new String[] { "Hallo!", "Bye!" } ) ));
        public static void main(String[] arg) {
            Test test = new Test();
            test.setVisible(true);
    }

    Hi again,
    yes it works when i set it for single column, but i'd like to use default editor, because column count is not fixed.
    According to documentation: "Sets a default cell editor to be used if no editor has been set in a TableColumn. If no editing is required in a table, or a particular column in a table, uses the isCellEditable method in the TableModel interface to ensure that this JTable will not start an editor in these columns. If editor is null, removes the default editor for this column class."
    So when i call
    column.setCellEditor(null); in TableColumnModelListener columnAdded event. But still it's not working. See sample below (i've changed it to cell renderer coz result is clear on single view, but problem stays same)
    More over problem seems to be with algoritm that decide which class to use. Object takes preference any time. W/o it npe arries.
    Regards
    Adam
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.DefaultTableModel;
    public class Test extends JFrame {
        JTable table;
        Test() {
            // Create table model
            table = new JTable();
            table.setModel(new DefaultTableModel(
                new Object[][] {
                    { Boolean.TRUE, Integer.valueOf(10) },
                    { "Hallo!", Boolean.FALSE },
                }, new String[] { "Col1", "Col2" }));
            // Setup frame a little
            setLayout(new BorderLayout());
            setBounds(new Rectangle(300,300,200,100));
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            add(table,BorderLayout.CENTER);
            table.setDefaultRenderer(Object.class,new Renderer(Color.YELLOW));
            table.setDefaultRenderer(String.class,new Renderer(Color.BLUE));
            table.setDefaultRenderer(Boolean.class,new Renderer(Color.RED));
            table.setDefaultRenderer(Integer.class,new Renderer(Color.GREEN));
            // use default renderer in all columns
            table.getColumn(table.getColumnName(0)).setCellRenderer(null);
            table.getColumn(table.getColumnName(0)).setCellRenderer(null);       
        public static void main(String[] arg) {
            Test test = new Test();
            test.setVisible(true);
        class Renderer extends DefaultTableCellRenderer {
            Color color;
            Renderer(Color color) { this.color = color; }
            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);
                setToolTipText("Class is "+value.getClass().getName());
                return this;
    }Message was edited by:
    a3cchan

  • How to set a cell editable at runtime for jtable

    Hi evry body
    i need to set a cell as editable during runtime and set some value for the cell and make it non editable after setting value
    how can i do it? urgent help appreciated
    regards
    anil

    You could override the methods isCellEditable(...) and setValueAt(...) in your JTable's TableModel to get the effect desired
    // Assuming that each element of the array will be false initially
    boolean[][] valueSet = new boolean[noRows][noCols];
    public boolean isCellEditable(int row, int col) {
      return !valueSet[row][col];
    public void setValueAt(Object obj, int row, int col) {
      super.setValueAt(obj, row, col);
      valueSet[row][col] = true;
    }

  • Setting jtables cell color

    Hi,
    I would like to know if anyone know how to set a specific cell colour in a JTable, or if they know any links to when i can find help...thanks in advance
    Rudy

    Take a look at TableCellRenderer and its default implementation
    HTH
    Mike

  • How to set JTable column's color?

    How can I set JTable Columns' color? I only found this class DefaultTableCellRenderer
    which can set cell's color.

    rmalina wrote:
    You are going to need to derive a renderer class for your Column from DefaultTableCellRenderer and override the following function with something like this:
    @Override
         public Component getTableCellRendererComponent(JTable jTable, Object oValue, boolean isSelected, boolean hasFocus, int nRow, int nColumn) {
    super.setForeground(Color.GREEN);
    super.setBackground(Color.GREEN);
    }That would set your column to green.
    Edited by: rmalina on Jul 28, 2008 8:47 AMHow can I know I only change the columns' color instead of other cells?

  • How to set the cell size in a JFrame

    Hello. Is there any way of setting the cell size in a JFrame. The reason why I want to set the cell size is that I want to be sure of their location that when I am placing components on the JFrame. So is there any way of setting the cell size beforehand. Also for the following code.
    JFrame frame = new JFrame("Window");
    frame.setSize(100,100);is the size 100 by 100 is he size of the cell?

    smithbrian wrote:
    When I am placing a component on the grid I want to be sure the component is exactly where I place it. In order to do that I would need to know what is the size of the gird and how to change the size of the gird in the JFrame.What grid?? You're assuming that we know much more about your program than we actually do. We actually know zip. Please read this help site which will help you to avoid similar errors in posting questions here. It has helped me in the past: [smart questions|http://www.catb.org/~esr/faqs/smart-questions.html]

  • How to manipulate jtable cell?

    Hi experts,
    I created a jtable with a BC4J related to the jtable.
    I do not know how to update a cell and how to insert a new row in the jtable.
    Would someone please tell me where I can find the document about manipulating a jtable?

    Have a look at the source code of JUNavigationBar. In that class, look for JUActionBinding(_buttons[BUTTON_FIRST]   , bind, JUActionBinding.ACTION_FIRST, false);As you can see you will need the JUActionBinding class.

  • How to use Jtable cell Editor

    HI,
    Here trying to populate the ImageIcon using JLabel in Jtable cell. For that I used DefaultCellRenderer. For implement the mouseListener to label I used the DefaultCellEditor. I am facing one problem here. After editing the label I selected the second row of the table, the first row image is not displaying. Can any one help on this issue?
    public class LabelCellEditor extends DefaultCellEditor {
    public LabelCellEditor(final JCheckBox checkBox) {
    super(checkBox);
    public Component getTableCellEditorComponent(final JTable table, final Object value,
    final boolean isSelected, final int row, final int column) {
    Color background = null;
    background = ColorManager.SELECTED_ROW_BGCOLOR;
    labelVal = (JLabel) value;
    labelVal.setOpaque(true);
    labelVal.setFont(FontManager.TABLE_DATA_FONT);
    labelVal.setBackground(background);
    labelPanel = new JPanel();
    labelPanel.setOpaque(true);
    labelPanel.setBackground(background);
    labelPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    labelPanel.setBorder(new EmptyBorder(5, 0, 0, 0));
    labelPanel.add(labelVal);
    return this.labelPanel;
    public Object getCellEditorValue() {
    return this.labelPanel;
    public class LabelCellRenderer extends DefaultTableCellRenderer {
    public LabelCellRenderer(final int alignment) {
    //setHorizontalAlignment(alignment);
    this.align = alignment;
    public Component getTableCellRendererComponent(final JTable table, final Object value,
    final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    if (value != null) {
    if (value instanceof JLabel) {
    labelVal = (JLabel) value;
    labelVal.setOpaque(true);
    labelVal.setFont(FontManager.TABLE_DATA_FONT);
    labelVal.setBackground(background);
    labelVal.setHorizontalAlignment(this.align);
    labelVal.setBorder(new EmptyBorder(0, LRPADD, 0, LRPADD));
    JPanel panel = new JPanel();
    panel.setOpaque(true);
    panel.setBackground(background);
    panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    panel.setBorder(new EmptyBorder(5, 0, 0, 0));
    panel.add(labelVal);
    return panel;
    return this;
    }

    With more than 30 postings you should know by now how to use the "Code" tags when posting code so the code reatains its original formatting and is therefore more readable.
    There is no need to create a custom editor, here is a simple example.

  • JTree: How to set different cell editor for different tree Nodes.

    I have a JTree and I want to set different cell editors for different node depending on some condition. E.g. I want to set ComboBox as editor for leaf node but each leaf node will have its own set of data.
    Any help or pointer?
    Thanks in advance
    Sachin

    take there:
    http://www.mutualinstrument.com/Easy/FAQ/Tree/tree.html

  • How to make Jtable cell empty onClick?

    Hi All,
    I have one requirement where I need to make the Jtable cell value empty on click or tab event. So, User does not have to do back space and delete whole string to edit that cell.
    Any idea?
    Thanks in advance.

    Hi camickr,
    Thanks for that reply. It did not work for me but Here is the thing.
    My requirement was : Client does not want to do back space in order do edit cell value when that cell clicked.
    I tried find the solution that, i can make that cell area as selected when it is clicked. my problem is solved. So, I tried to use Table select all editor.
    But here is what i found ......
    If I want that cell area selected, I need to do one more click(3 clicks at the same time) to select the value of that cell & I can put my new value without doing back space(stupid client requirement)
    Thanks for your help

  • How to access jtable cells in multiple tabs?

    Hi,
    in my program when I push a button 3 tabs are created. And all these tabs have a table in it. What I want to do is that When I push other button I want to access all these tables and cells. and get the cell values. How can I get the value of one cell in the jtable when I have multiple tabs?
    thanks in advance.

    This is my main window
    public class AuditClient extends javax.swing.JFrame {
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    createCheckList();
    public void createCheckList() {
    CheckList.createCheckList(CheckListChildPane);
    private javax.swing.JTabbedPane CheckListChildPane;
    private javax.swing.JPanel CheckListParentPanel;
    And This is the CheckList.java : This code create tabs and tables in it. (from xml file).
    public class CheckList extends JPanel implements ActionListener{
    JTable table;
    public CheckList(Object[][] TheData) {
    MyTableModel model = new MyTableModel();
    model.setData(TheData);
    table = new JTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    add(scrollPane);
    class MyTableModel extends AbstractTableModel {
    public String[] columnNames = null;
    public Object[][] data = null;
    public final Object[] longValues = null;
    public void setColumnNames(String[] cols) {
    this.columnNames=cols;
    public void setData(Object[][] datas) {
    this.data=datas;
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return data.length;
    public String getColumnName(int col) {
    return columnNames[col];
    public Object getValueAt(int row, int col) {
    return data[row][col];
    public Class getColumnClass(int c) {
    return getValueAt(0, c).getClass();
    public static void createCheckList(JTabbedPane CheckListChildPane) {
    //creates tabs and tables in it
    I want to access the tables (which I created in CheckList java) from my main window. I want to get the cell values of these tables
    thanks

  • How to set JTable row background color

    Hello,
    I have seen JTable with rows having alternate background color (mostly white and light blue). How can i set the same.
    Thanks,
    Deepak

    Well, i am new user to forum and so have no idea if this question has been asked previously "countless" times.Which is why you "search first" and "ask later". How to you expect to find out what valuable information is in the forum without learning how to do a simple search. This goes for any forum on the web you might use, so don't use the "I'm a new user" excuse.

Maybe you are looking for

  • I have 2 apple ID's, how do i get rid of one?

    I am really confused with the whole apple ID concept. I believe i have 2 apple ID's. One i had set up for my daughter and her ipod and one i thought was mine. Though my phone seems to have the ID i used for my daughter always in as default. I tried t

  • Can't print wirelessly to HP6500 that is successful​ly connected

    I am getting Error-Printing when try to print anything to wirelessly connected HP6500 Wireless. Printer is successfully connected to wireless home network: Wireless Network Test Report gives IP address and says all status is PASSED. When type IP addr

  • Origin of Sales Tax ID Number in billing document

    Hi In the billing Header, Taxes, there is a field "Origin of Sales Tax ID Number". Can you pls. guide me what is the mean of this field and how the value for that particular field is detemined. with regards

  • Trying to install Classic in OS 10.4.3

    Hi, The CD that came with the lap top is OS 10. I dont have any cds that is older than OS 10. I am unable to run many of the application without the Classic Environment. I am unable to run even small applications or for that matter install any study

  • Authorisation in workflow - Urgent

    Hi Workflow Experts, I have one req with Error message dispaly. requirment with when ever User accessed work items in business workplace in R/3 System then Error Message should display. when ever work items for portal access then user can access. for