Setting different editors in different cells in a single column

Hi,
My approach to setting different editors like JTextField,JComboBox etc to different cells in a single column is not upto fully satisfactory. As compiling the same code lower than 1.5 gives error in that line. My approach is as follows:
..................// other implementations
DefaultCellEditor comboeditor,texteditor;
JTextField tf=new JTextField();
texteditor=new DefaultCellEditor(tf);
texteditor.setClickCountToStart(2);
JComboBox cb=new JComboBox("its_value_is_already_set");
comboeditor=new DefaultCellEditor(cb);
comboeditor.setClickCountToStart(2);
DefaultTableModel model=new DefaultTableModel(datas,colNames);
JTable table=new JTable(model){
  public DefaultCellEditor getCellEditor(int row,int col)
     if ((row==0) && (col==1))
        setCellEditor(texteditor);
        return texteditor;
     else if ((row==1) && (col==1))
         setCellEditor(comboeditor);
         return comboeditor;
};The thing wat shows error while compiling in version lesser than 1.5 is in the getCellEditor(int row,int col) return type as it should be TableCellEditor not the DefaultCellEditor. But anyhow it works with 1.5 but show error in lesser version as I already said. So, wat can be the perfect code for it please help me fix it.
regards,
Jay

Sorry, I forgot to mention the return statement if neither of the conditions r met in the if..else clause. I've written return (DefaultCellEditor)super.getCellEditor(). Now wats the difference in using super.getCellEditor() & super.getCellEditor(row,col). Excluding the setCellEditor(...) method is my code fine. I mean is it acceptable for other versions as I'm still confused with the return type that I have included instead of the required one... like DefaultCellEditor instead of TableCellEditor.
regards,
Jay

Similar Messages

  • JTable - different editor for each cell?

    I have a JTable where two columns have combo box editors. When the user makes a selection in one combo box, the other combo box's options must change, as its allowable options depend on selection in the other combo box.
    So in short, I need a way of changing the combo box options for ONLY a specific cell, NOT the entire column. I currently only know how to do this for a whole column:
    // first put stuff in myComboBox, and then...
    myJTable.getColumnModel().getColumn().setCellEditor( new DefaultCellEditor( myComboBox ) );
    Is there any way to change the values in the combo box of a specific cell, rather than the entire column?
    I apologize if this is a newbish question... I am fairly new to Swing, but I didn't see anything addressing this in the documentation.
    -Vern

    The solution is like the one I gave you in one of
    your previous postings. In that posting you wanted a
    renderer for a specific cell. In this posting you
    want a editor for a specific cell. The solution is
    the same, only the method name changes.Okay, thanks. Sorry if it seems like I'm a slow learner. ;-)
    -Vern

  • Setting JcomboBox editor for a table cell

    Hi,
    I have a ComboBox editor for a cell in my table. I want to set this editor depending on the value of another column
    qualifierTable.addMouseListener(new MouseAdapter(){
       public void mouseClicked(MouseEvent e){
        int selRow = qualifierTable.getSelectedRow();
        int selCol = qualifierTable.getSelectedColumn();
       if (someCondition)
                JComboBox comboBoxEditor = new JComboBox();
                comboBoxEditor.addItem("Private");
                 comboBoxEditor.addItem("Protected");
                 comboBoxEditor.addItem("Public");
                 qualDataValueCol.setCellEditor(new DefaultCellEditor(comboBoxEditor));
                 Object dataValue = comboBoxEditor.getSelectedItem();
                                          if (dataValue!= null)
                 {                              qualifierTablemodel.setValueAt(dataValue, selRow, selCol);
    }The problem is this sets the editor for all cells in the column. However I want the editor to revert to JTextField if this condition is not met. Where should I set it back. It does not work if I set it in the else part

    Override the getCellEditor(...) method to return the appropriate editor. Something like this:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=637581

  • 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 set different renderers to different cells in same column of JTable?

    Hello Friends,
    I need your help again...
    Does any body knows, how to set different renderer's for different cells of same column in JTable..??
    For ex.
    Col1 Col2 Col3 Col4
    A       A       A      A
    A       A       A      B
    A       A       A      C
    A       A      A       D
    Where A B C D would be different Renderers.  I want set exactly same ,,, ie. one column with different renderer at different cell positions..
    Right now i m setting renderer using statement bellow :
    table.getColumnModel().getColumn(int).setCellRenderer(rederer_Instance);But with this, effect in the last renderer is applicable whole column....
    Can any body help me out ?????????
    please refer this thread for similar kind of discussion...
    http://forums.sun.com/thread.jspa?forumID=57&threadID=571445Thanks
    Suyog

    Please refer to the first reply of [this thread|http://forums.sun.com/thread.jspa?forumID=57&threadID=571445] for the answer. If you have a specific problem implementing it, post you code with a specific question.

  • How to set two different UIE in one cell in ALV table

    Hi all,
    I have a hierachy ALV table. For some reason I want to have two UI elements in one column. For example, the text and a menu next to the text. Is it possiable to do that?
    best regards,
    Wenwen

    Hi,
    thank you for your answer. Yes, now I also find the class CL_SALV_WD_MULTI_CELL_EDITOR which could be used to set different UIE in one cell. But it is quite limited, just the following UIE could be used
    - LinkToAction 
    - LinkToURL    
    - FileDownload 
    - Button       
    - ToggleButton 
    best regards,
    Wenwen

  • Setting different Tabel Cell SemanticColor for Multiple Columns of each row

    Hi,
    I have requirement of setting different colors to different columns for each row based on some condition in table data.
    The data to table is coming from model, hence table is mapped to model node and attributes.
    I have created Seperate Node CellColorNode with attribue CellClr1 and CellClr2 of type TextView Semantic Color.
    Set the calculated, read only attribute to True. Mapped table columns text view to the CellColorNode->CellClr1 and CellColorNode-->CellClr2 correspondingly.
    Now, my query is how do i set the colors to CellClr1 and CellClr2 attributes. As I need to set the color for multiple columns of each table row.
    Is it in method getColorCellCellClr generated? Any  Example Code?

    Its resolved by following below link
    http://scn.sap.com/thread/158286

  • Setting cell editor for individual cell in JTable

    Hi there,
    I want to provide individual cell editor for my JTable. Basically, my JTable shows property names and values. I want to show different cell editors for different properties.
    I followed the advice in this post:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=423318
    but I have a question:
    I looked at the code of DefaultCellEditor. It just has a single editor component (the one provided in the constructor), so all the methods use the same component and certain aspects are customized for the type of component. Again, there can be only one type of component at a time.The problem that I am facing is that I will have different components for different row/column of the same table. So how do I implement some of the methods (for example, getCellEditorValue()), when I have multiple editor components?
    Also, how do I commit changes made by the user?
    I am extremely confused.
    Someone please help!
    Thanks.

    Actually, that's what I am currently doing.
    Here is my cell editor class:
    public class ObjectPropertyEditor extends DefaultCellEditor
           public ObjectPropertyEditor()
              super(new JTextField());
              Vector list = new Vector();
              list.add("Yes");
              list.add("No");
             myCombo = new JComboBox(list);
          public Component getTableCellEditorComponent(JTable table, Object value,
              boolean isSelected, int row, int column)
             String colName = (String)table.getValueAt(row,0);
             if(colName.equalsIgnoreCase("Leaf-Node?")) //if it is the "Leaf" property, return the combo box as the editor
                 return myCombo;
            else  //for all other properties, use JTextField of the super class
                return super.getTableCellEditorComponent(table,value,isSelected,row,column);
        private JComboBox myCombo;
    }The problem I have is that when I select a new item from the combo box, the new selection is not reflected in the tableModel. I don't know how I can achive that. I think I need the functionalities that DefaultCellEditor gives to its delegate when its constructor arguments is a combo box. But how can I get two different sets of functionalities (JTextField and JComboBox) ?
    Please help!
    Thanks.

  • Different format in one cell by formula?

    Hi there,
    does someone know if it is possible to grab and connect text with the & operator and set different formats (bold, italic...) with a command in the formula?
    For example I have different lines in one cell done with the CHAR(10) and want to have the last line in bold format. Is this kind of manipulation possible?

    As far as I know, there is no such function.
    We may apply different styles in a cell by hand, not by a formula.
    I checked that the concatenation of the contents of cells with different styles result with a string in standard style.
    Yvan KOENIG (from FRANCE samedi 13 décembre 2008 19:44:03)

  • Different JComboBox in different Cells in a JTable

    Hi:
    I would like to make a JTable whose content would be several JBox with different values each one. That is to say, a double-column table with the value name in the first column and a range of possible values in the second column,
    Despite my efforts I was not able to do that. Every example that I found in the Web does not let different JComboBox per cell. They run with the same cell and values for each column.
    Can anybody help me?
    Thanks in advance.
    Carlos

    Here is an example that is based on camickr´s example:
    import javax.swing.DefaultCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.*;
    import java.util.*;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.table.*;
    import javax.swing.JTable;
    import java.util.ArrayList;
    import javax.swing.DefaultCellEditor;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    public class TableCell extends JFrame
         JComboBox comboBox1 = new JComboBox();
         JComboBox comboBox2 = new JComboBox();
         JTable table;
         ArrayList<DefaultCellEditor> editors = new ArrayList<DefaultCellEditor>();
         TableCell()
              comboBox1.addItem("Tennis");
              comboBox1.addItem("Fotboll");
              comboBox1.addItem("Baseball");
              comboBox1.addItem("Handboll");
              comboBox2.addItem("USA");
              comboBox2.addItem("Brazil");
              comboBox2.addItem("Australia");
              comboBox2.addItem("China");
              comboBox2.addItem("Egypt");
              DefaultCellEditor dce1 = new DefaultCellEditor(comboBox1);
              DefaultCellEditor dce2 = new DefaultCellEditor(comboBox2);
              editors.add(dce1);
              editors.add(dce2);
              final JTable table = new JTable()
              { // anonym innerklass
                   private Class editingClass;
                   public TableCellRenderer getCellRenderer(int row, int column)
                        editingClass = null;
                        int modelColumn = convertColumnIndexToModel(column);
                        int modelRow = convertRowIndexToModel(row);
                        if (modelColumn == 1)
                             Class rowClass = getModel().getValueAt(row, modelColumn).getClass();
                             return getDefaultRenderer( rowClass );
                        else
                             return super.getCellRenderer(row, column);
                   public TableCellEditor getCellEditor(int row, int column)
                        editingClass = null;
                        int modelColumn = convertColumnIndexToModel(column);
                        int modelRow = convertRowIndexToModel(row);
                        if (modelColumn == 1)
                             if (modelRow == 5)     // cell number 5 in column 1 which is going to show the combobox
                                  return (DefaultCellEditor) editors.get(0);
                             if (modelRow == 6)     // cell number 6 in column 1 which is going to show the combobox
                                  return (DefaultCellEditor) editors.get(1);
                             else
                                  editingClass = getModel().getValueAt(modelRow, modelColumn).getClass();
                                  return getDefaultEditor( editingClass );
                        else
                             return super.getCellEditor(row, column);
              table.setModel(new javax.swing.table.DefaultTableModel
                   new Object [][]
                          {"String", "I'm a string"},
                        {"Date", new Date()},
                        {"Integer", new Integer(123)},
                        {"Double", new Double(123.45)},
                        {"Boolean", Boolean.TRUE},
                        {"Combobox 1", "COMBOBOX 1"},
                        {"Combobox 2", "COMBOBOX 2"}
                   new String [] { "Attribute", "Data" }
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
         public static void main(String[] args)
              TableCell frame = new TableCell();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

  • Multiple small stories with variable line counts assigned to different editors

    I have a "best practice" question for you more experienced InCopy users about what workflow you recommend for my specific issue. I am experienced in InDesign, but am a InCopy newbie. I want to make sure I'm not missing a solution because my lack of experience with InCopy may be causing me not to see the forest for the trees.
    Short version: What is the best way to allow multiple editors access to each of multiple small stories separately (one story per editor), but to allow the line count of each story to be variable each week, while adjusting the rest of the stories along with it on the page (see image below)?
    Details: My publishing company's workflow is on CS6 with editors working in Word, and we're upgrading to CC2014 with InCopy. We have 7 in-house editors, and all files on an in-house server. We have quick deadlines (some are 15 minutes from editor writing copy to transmitting publication to subscribers). In the example below, we have 10 sections, and I have all seven editors writing different sections at the same time. A final editor has control over fitting the final page. My INDD files to test the new workflow use an assignment-based workflow. I understand I can place each of these sections as their own story, under the same assignment, so a different editor can have them checked out. However, each section does not have the same line count from week to week. Markets with more activity will get more lines.
    In our current workflow, we have multiple rough Word docs pulled into one master doc with a script, that the final editor edits to fit, so each section can be a different number of lines as long as the total is the same. Then production staff load it in. When we upgrade, we can use a hybrid workflow where the final editor just loads that final Word doc into one InCopy story and edits it to fit.
    It would be great if I just didn't understand how to make the text height variable for the story each editor is typing, and auto-adjust so the next story starts below where the story above it ends, and you all had an idea how I can do it!
    Thanks! Nancy

    I disagree to Seshu's answer to question 1.
    Correct answer of question 1 is C and <u><b>not A.</b></u>
    Sorry I didn't find time to check the rest.
    <u>To the examinee</u>
    I wouldn't assume all answers from SDN-ers are correct if my certification exam was knocking the door! I would rather try and find out the correct answers myself from the system instead of mugging these answers without any understanding of the technology involved! Find out the answers yourself from the system...that way it will help you to understand why the answer is 'C' and not 'A'...just knowing the answer is 'C' is not good enough...one has to understand "why" its 'C' and not 'A'. Hope you get my point! Good luck.

  • Hi, I have an iTunes account on my laptop set up to work with my old iPod. I now have an iPad and new iPod but set up under a different account- can I put all the songs from my iTunes onto the new devices. Thanks.

    Hi, I have an iTunes account on my laptop set up to work with my old iPod. I now have an iPad and new iPod but set up under a different account- can I put all the songs from my iTunes onto the new devices. Thanks.

    Yes
    Put all the music on one computer, make sure it is authorized for all accounts, sync.

  • How do I uninstall the software from my computer to start the iPhone set up over again, as I have managed to set everything to several different email accounts, and want it all to operate from one?

    I Have managed to set my software to different email accounts as I already had an apple acount to one email address because of my iPod, so I set it so my old email which is full of spam, making it impossible to organise. Therefore I created a new email which I can use efficiently, but how do I reset my account on my iPhone and the software on my computer so it can all operate as one? Please HELP!

    iPhone User Guide (For iOS 4.2 and 4.3 Software)

  • My Apple TV was set up with a different Apple ID than I have for my ITunes Account.  In other words I have multiple Apple ID's.  How can get these accounts to sync up?

    My Apple TV was set up with a different Apple ID than I have for my ITunes Account.  In other words I have multiple Apple ID's.  How can get these accounts to sync up?

    If you wish to use home sharing then you need to setup the Apple TV under your ID.

  • ITunes i have downloaded some movies.  i have an apple tv set up under a different account.  how can i stream the movies from my pc to someone else's apple tv?

    i have a windows based pc and on iTunes i have downloaded some movies.  i have an apple tv set up under a different account.  how can i stream the movies from my pc to someone else's apple tv?

    If you wish to use home sharing then you need to setup the Apple TV under your ID.

Maybe you are looking for