Results 1 to 5 of 5

Thread: What is the use of AbstractCellEditor class?

  1. #1
    Join Date
    Dec 2009
    Posts
    67

    What is the use of AbstractCellEditor class?

    Hello Guys,

    I just started to learn advanced java programming. I am totally confused about the 'AbstractCellEditor class'. I have to use this java class in my project which is based on java programming. But unfortunately I don't have any idea about AbstractCellEditor class. If you posses sound knowledge about the AbstractCellEditor class of java then please try to share it with me. Your help would greatly appreciated.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What is the use of AbstractCellEditor class?

    A AbstractCellEditor class defines the methods any general editor should be able to implement. Having this class enables complex components (the client of the editor) such as JList, JTree, and JTable to allow any generic editor to edit values in a table cell, or tree cell, etc. Without this generic editor interface, JTable would have to know about specific editors, such as JTextField, JCheckBox, JComboBox, etc. In addition, without this interface, clients of editors such as JTable would not be able to work with any editors developed in the future by the user or a 3rd party ISV.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: What is the use of AbstractCellEditor class?

    Hi friend,

    Following example of java code will demonstrate you the use of AbstractCellEditor class:
    Code:
    import javax.swing.AbstractCellEditor;
    
    public class AbstractCellEditorMain {
      public static void main(String arrgs[]) {
        JFrame dMp = new JFrame("Editable Color Table");
        dMp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        TableModel model = new ColorTableModel();
        JTable table = new JTable(model);
        TableColumn column = table.getColumnModel().getColumn(2);
         TableCellEditor editor = new ColorChooserEditor();
        column.setCellEditor(editor);
        JScrollPane scrollPane = new JScrollPane(table);
        dMp.add(scrollPane, BorderLayout.CENTER);
        dMp.setSize(300, 150);
        dMp.setVisible(true);
     }}
    
    class ColorChooserEditor1 extends AbstractCellEditor implements TableCellEditor {
    
      private JButton delegate = new JButton();
    
      Color savedColor1;
    
      public ColorChooserEditor() {
        ActionListener actionListener = new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            Color color01 = JColorChooser.showDialog(delegate, "Color Chooser", savedColor);
            ColorChooserEditor.this.changeColor(color01);
          }    };
        delegate.addActionListener(actionListener);
      }
    
      public Object getCellEditorValue() {
        return savedColor1;
      }
      private void changeColor(Color color01) {
        if (color01 != null) {
          savedColor = color01;
        }  }
    
      public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
          int row, int column) {
        changeColor((Color) value);
        return delegate;
      }
    }

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What is the use of AbstractCellEditor class?

    I recommend you to review following methods of AbstractCellEditor class along with their parameters:
    • shouldSelectCell(EventObject anEvnt)
    • removeCellEditorListener(CellEditorListener ls)
    • isCellEditable(EventObject evnOb)
    • addCellEditorListener(CellEditorListener ls)
    • getCellEditorListeners()

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: What is the use of AbstractCellEditor class?

    Hi,

    Below I have the example of AbstractCellEditor class, In which I have ised the various methods of this java class:
    Code:
    import java.awt.BorderLayout;
    import java.awt.Color;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JCheckBox;
    
    public class CheckBoxNodeTreeDM {
      public static void main(String ags[]) {
        JFrame frame003 = new JFrame("CheckBox Tree");
    
        CheckBoxNode accessibilityOptions[] = {
            new CheckBoxNode(
                "Move system caret with focus/selection changes", false),
            new CheckBoxNode("Always expand alt text for images", true) };
        CheckBoxNode browsingOptions[] = {
            new CheckBoxNode("Notify when downloads complete", true),
            new CheckBoxNode("Disable script debugging", true),
            new CheckBoxNode("Use AutoComplete", true),
            new CheckBoxNode("Browse in a new process", false) };
        Vector accessVector = new NamedVector("Accessibility",
            accessibilityOptions);
        Vector browseVector = new NamedVector("Browsing", browsingOptions);
        Object rootNodes[] = { accessVector, browseVector };
        Vector rootVector = new NamedVector("Root", rootNodes);
        JTree tree01 = new JTree(rootVector);
    
        CheckBoxNodeRenderer renderer = new CheckBoxNodeRenderer();
        tree01.setCellRenderer(renderer);
    
        tree01.setCellEditor(new CheckBoxNodeEditor(tree01));
        tree01.setEditable(true);
    
        JScrollPane scrollPane1 = new JScrollPane(tree01);
        frame003.getContentPane().add(scrollPane1, BorderLayout.CENTER);
        frame003.setSize(400, 150);
        frame003.setVisible(true);
      }
    }

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  3. Difference among concrete class and abstract class
    By Roxy_jacob in forum Software Development
    Replies: 4
    Last Post: 07-12-2009, 01:22 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 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,750,812,205.60230 seconds with 16 queries