Tableview custom cell problem

Hi everyone.
I created a iOS tabbed application using xcode 4.2 and storyboard. I added one tableviewcontroller with custom cell on it, when clicking the row, I want to open one tableviewcontroller, i used the following code below
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    categoryClass *cc = [datas objectAtIndex:indexPath.row];
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    iSubProducts *subProducts = [[iSubProducts alloc] init];
    subProducts.title = cc.categoryName;
    subProducts.catID = cc.categoryID;
    [[self navigationController] pushViewController:subProducts animated:YES];
    [subProducts release];
but when I click the row it gives me the following error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath
on my iSubProducts tableviewcontroller, i have the following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    static NSString *CellIdentifier = @"myCell2";
    iSubProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    productSubClass *cc = [datas2 objectAtIndex:indexPath.row];
    NSLog(@"Product Name: %@", cc.productName);
    cell.txtProductName.text  = cc.productName;
    cell.txtProductDesc.text = cc.productDesc;
    return cell;
I assume this is where the error occurs, the cell is returning a nil value. When I try to attach the iSubProducts tableviewcontroller using or from a button, it all works fine, but if its coming from row clicked, this error shows up.
Im quite new with iOS development, and maybe there is a error opening tableviewcontroller from a tableviewcontroller with a custom cell on it. I've been bangin my head for 2 days now and googled a lot, unfortunately I didn't find any solution. I'm pretty sure there's no error on the iSubProducts tableviewcontroller since its working if i tried pushing it from a button. Please I need advice on this one, Im so stucked right now with this issue. Thank you everyone.

Hi,
you need to create a tableViewCell in case the dequeueReusableCell-call doesn't return one.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    static NSString *CellIdentifier = @"myCell2";
    iSubProductsCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
        cell = (iSubProductCell *)[[UITableViewCell alloc] init....
    productSubClass *cc = [datas2 objectAtIndex:indexPath.row];
    NSLog(@"Product Name: %@", cc.productName);
    cell.txtProductName.text  = cc.productName;
    cell.txtProductDesc.text = cc.productDesc;
    return cell;
Dirk

Similar Messages

  • [iPhone] Custom UITableViewController and selecting cell problem.

    Hello,
    I'm creating a custom table view controller by declaring a UIViewController and adopting the UITableViewDataSource and UITableViewDelegate protocol.
    With my current implementation, if I select a cell to transition to another view and then navigate back to the tableview, the cell will remain selected.
    There must be some delegate method I am not implementing.
    If I update the header file of my table view controller by removing the adopted protocols and subclassing the UITableViewController, I dont have this "selection sticking" problem.
    Any ideas as to what I am doing wrong?
    Thanks!

    You're not doing anything wrong, except by omission. If you choose to implement a table view controller as a UIViewController rather than a UITableViewController, you are responsible for controlling selection/deselection of the cells on returning back to the table view from some child view. In the common case where something going on in the child controller affects what cell should be selected/deselected on returning back to the parent table view, this is exactly what you want, because the UITableViewController doesn't always get it right, to sometimes comical effect.
    How you would set this up is highly context-dependent.
    Doug

  • Row Selection problem in custom cell renderer

    Hi,
    I have created a custom cell renderer to set color in my table based on some value and the screen also shows colors when i set this cell renderer.
    But, I am not able to see the row selection ie. with blue background when I select any row in the table is nor appearing. Can you tell me how to solve this problem.
    Regards,
    R.Vishnu Varadhan.

    Check out this [url http://forum.java.sun.com/thread.jsp?forum=57&thread=507001]thread for a similiar example.

  • JTable custom cell editor focus problem

    Hi I have created a JTable (using Java 1.4.2) and have three cell Editors, one is a JFormattedTextField, one is a JComboBox and one is a custom cell editor.
    When I press tab I can select the cell with the JFormattedTextField and when I start typing the JFormattedTextField accepts my input and it is displayed in the cell. This is the type of behaviour I would like but it does not seem to work for my other 2 cell editors:
    When I tab to the JComboBox cell I can see that the cell is selected but typing or using the arrow keys does not allow me to select a new value in the JComboBox. (I have also tried typing space or enter to activate the JComboBox whilst the cell is selected.) The only ways to select a new value at the moment is to first click on the cell with the mouse and then use the keyboard to select a new value. It is like the actual JComboBox is not receiving the focus? Does anyone know how to solve this problem?
    I also seem to have the same problem with my custom cell editor. My custom editor is a JPanel which contains JFormattedTextField again I can tab to the cell and see that it is selected but to activate the JFormattedTextField I have to actually select it with the mouse.
    I have been stuck on this for some time so if any one has any suggestions they would be much appreciated !

    Hi I have created a JTable (using Java 1.4.2) and have three cell Editors, one is a JFormattedTextField, one is a JComboBox and one is a custom cell editor.
    When I press tab I can select the cell with the JFormattedTextField and when I start typing the JFormattedTextField accepts my input and it is displayed in the cell. This is the type of behaviour I would like but it does not seem to work for my other 2 cell editors:
    When I tab to the JComboBox cell I can see that the cell is selected but typing or using the arrow keys does not allow me to select a new value in the JComboBox. (I have also tried typing space or enter to activate the JComboBox whilst the cell is selected.) The only ways to select a new value at the moment is to first click on the cell with the mouse and then use the keyboard to select a new value. It is like the actual JComboBox is not receiving the focus? Does anyone know how to solve this problem?
    I also seem to have the same problem with my custom cell editor. My custom editor is a JPanel which contains JFormattedTextField again I can tab to the cell and see that it is selected but to activate the JFormattedTextField I have to actually select it with the mouse.
    I have been stuck on this for some time so if any one has any suggestions they would be much appreciated !

  • Problem with UITableViewCell, can´t add the same custom cell

    Hi,
    I have a table view which I populate the cells with a UITableView class that i wrote. This custom class has two labels and a image view. In the method cellForRowAtIndexPath, i use the following code:
    [cell addSubview:myTableViewCellClass];
    the first cell is ok, the cell displays my custom cell. But the second cell can´t display the same custom cell object. Is there something I can do to avoid this problem?
    I have another problem. When i scroll my table view very fast, the program crashes with the following message:
    [Session started at 2008-08-24 18:30:10 -0700.]
    Loading program into debugger…
    GNU gdb 6.3.50-20050815 (Apple version gdb-960) (Sun May 18 18:38:33 UTC 2008)
    Copyright 2004 Free Software Foundation, Inc.
    GDB is free software, covered by the GNU General Public License, and you are
    welcome to change it and/or distribute copies of it under certain conditions.
    Type "show copying" to see the conditions.
    There is absolutely no warranty for GDB. Type "show warranty" for details.
    This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols >for
    "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
    warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
    warning: Unable to read symbols for "/System/Library/Frameworks>/CoreGraphics.framework/CoreGraphics" (file not
    found).
    warning: Unable to read symbols from "CoreGraphics" (not yet mapped into memory).
    Program loaded.
    sharedlibrary apply-load-rules all
    Attaching to program: `/Users/pitteri/Library/Application Support/iPhone
    Simulator/User/Applications/9F7BD517-CB1E-49C5-BD30-24831239120F/OndeEstou.app/O ndeEstou', process 11209.

    This is not the correct method for using custom table cells with a table. You need to create a custom cell class that extends UITableViewCell. This class should handle the layout and display for the content of a single cell.
    In your table view delegate's 'cellForRowAtIndexPath' method, you create or obtain an instance of your custom cell, configure the cell by setting the title or other properties appropriate for you custom cell, then return the cell. That's it.
    It appears, from your code, that you are trying to add the table view cell class to the cell. Maybe you mistyped. But don't call 'addSubview' on anything within the table view delegate.
    Have a look at the UICatalog example app. It has several custom table cells and shows both how to implement a custom cell, but also how to use it in a table.
    Enjoy.

  • Problem sorting JTable with custom cell editor

    Greetings,
    I have created a JTable with a JComboBox as the cell editor for the first column. However, I couldn't simply set the default cell editor for the column to be a JComboBox, since the values within the list were different for each row. So instead, I implemented a custom cell editor that is basically just a hashtable of cell editors that allows you to have a different editor for each row in the table (based on the ideas in the EachRowEditor I've seen in some FAQs - see the code below). I also used a custom table model that is essentially like the JDBCAdapter in the Java examples that populates the table with a query to a database.
    The problem comes when I try to sort the table using the TableSorter and TableMap classes recommended in the Java Tutorials on JTables. All of the static (uneditable) columns in the JTable sort fine, but the custom cell editor column doesn't sort at all. I think that the problem is that the hashtable storing the cell editors never gets re-ordered, but I can't see a simple way to do that (how to know the old row index verses the new row index after a sort). I think that I could implement this manually, if I knew the old/new indexes...
    Here's the code I use to create the JTable:
    // Create the Table Model
    modelCRM = new ContactTableModel();
    // Create the Table Sorter
    sorterCRM = new TableSorter(modelCRM);
    // Create the table
    tblCRM = new JTable(sorterCRM);
    // Add the event listener for the sorter
    sorterCRM.addMouseListenerToHeaderInTable(tblCRM);
    Then, I populate the column for the custom cell editor like this:
    // Add the combo box for editing company
    TableColumn matchColumn = getTable().getColumn("Match");
    RowCellEditor rowEditor = new RowCellEditor();
    // loop through and build the combobox for each row
    for (int i = 0; i < getTable().getRowCount(); i++) {
    JComboBox cb = new JComboBox();
    cb.addItem("New");
    //... code to populate the combo box (removed for clarity)
    rowEditor.add(i,new DefaultCellEditor(cb, i))); //TF
    } // end for
    matchColumn.setCellEditor(rowEditor);
    Any ideas how to do this, or is there a better way to either sort the JTable or use a combobox with different values for each row? Please let me know if more code would help make this clearer...
    Thanks,
    Ted
    import java.util.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    public class RowCellEditor implements TableCellEditor
    protected Hashtable editors;
    protected TableCellEditor editor, defaultEditor;
    public RowCellEditor()
    editors = new Hashtable();
    defaultEditor = new DefaultCellEditor(new JTextField());
    public void add(int row, TableCellEditor editor)
    editors.put(new Integer(row), editor);
    public Component getTableCellEditorComponent(JTable table,
    Object value,
    boolean isSelected,
    int row,
    int column)
    editor = (TableCellEditor) editors.get(new Integer(row));
    if (editor == null)
    editor = defaultEditor;
    return editor.getTableCellEditorComponent(table,
    value,
    isSelected,
    row,
    column);
    public Object getCellEditorValue() {
    return editor.getCellEditorValue();
    public boolean stopCellEditing() {
    return editor.stopCellEditing();
    public void cancelCellEditing() {
    editor.cancelCellEditing();
    public boolean isCellEditable(EventObject anEvent) {
    return true; //TF
    //return editor.isCellEditable(anEvent);
    public void addCellEditorListener(CellEditorListener l) {
    editor.addCellEditorListener(l);
    public void removeCellEditorListener(CellEditorListener l) {
    editor.removeCellEditorListener(l);
    public boolean shouldSelectCell(EventObject anEvent) {
    return editor.shouldSelectCell(anEvent);
    -------------------

    Well, I found a solution in another post
    (see http://forum.java.sun.com/thread.jsp?forum=57&thread=175984&message=953833#955064 for more details).
    Basically, I use the table sorter to translate the row index for the hashtable of my custom cell editors. I did this by adding this method to the sorter:
    // This method is used to get the correct row for the custom cell
    // editor (after the table has been sorted)
    public int translateRow(int sortedRowIndex)
    checkModel();
    return indexes[sortedRowIndex];
    } // end translateRow()
    Then, when I create the custom cell editor, I pass in a reference to the sorter so that when the getTableCellEditorComponent() method is called I can translate the row to the newly sorted row before returning the editor from the hashtable.

  • Event Handling in JTable Custom Cell Renderer

    I have a JLabel as a custom cell Renderer for a column. I want to handle mouse click event for the JLabel rendered in the cell.
    I tried adding the listener for the label in the custom cell renderer but it is not working. Any ideas how to handle this problem??
    Thanks
    S.Anand

    If you want to handle the selection of a tree node
    1) write a class like:
    public class TreePaneListener implements TreeSelectionListener {
    // TREE SELECTION LISTENER
    public void valueChanged(TreeSelectionEvent e) {
    JTree tree = (JTree)e.getSource();
    DefaultMutableTreeNode node = null;
    int count = 0;
    boolean doSomething = false;
    if(tree.getSelectionCount() > 1) {
         TreePath[] selection = tree.getSelectionPaths();
         int[] temp = new int[selection.length];
         for(int i =0; i < selection.length; i++) {
    // Check each node for selection
         node = (DefaultMutableTreeNode)selection.getLastPathComponent();
         if(node.getLevel()==2) {
    // Change this code to take the action desired
         doSomething = true;
    2) After creating the tree register the listener
    TreePaneListener handler = new TreePaneListener();
    tree.addTreeSelectionListener(handler);

  • Customer Service Problems

    After fighting with Verizon customer service over two service issues without any possibility of resolution I am canceling my account. 
    I’m doing this reluctantly because as a long-term shareholder of Verizon I would like to see the company succeed and keep profitable.  Yet I am appalled by the cavalier, disrespectful, obstructionist treatment from your staff in dealing with customer service problems.  When you were just the telephone company and operated as a monopoly in a regulated industry, you had to take customer issues seriously.   Now that you are an unregulated telecommunications giant it seems that you don’t feel the need to respond to your customers.  Someone in your company needs to hear this and put a stop to these destructive business practices. 
    In brief, the first issue involved arranging a service call for interruption of internet service.  The entire process kept me on the phone for a total of 3 hours over several days.  I have given up my land line and use a cell phone exclusively.  Verizon’s communication systems and staffing levels caused me to wait on hold for 10-15 for each person that I spoke to. Then each conversation averaged 10 minutes.   In addition, I was transferred to different departments but  I did not understand the reason for the transfers.  Then the pattern of hold-talk-transfer began again.  Several times my calls were dropped necessitating more repeats of the hold-talk-transfer pattern.  Some of your staff were South Asian and they either garbled or misunderstood English, thus prolonging the conversation beyond the average of 10 minutes.    During that time I incurred cell phone charges of $.45/ minute.   
    After the service was restored I called Verizon customer service and asked for a service credit to compensate me for those out-of-pocket expenses over and above 30 minutes which I consider to be a reasonable amount of time to arrange a service call.  They denied any responsibility for the amount of time it took to arrange the service call or the amount of time to complain about their service.  I was not happy with the outcome so I requested to speak with someone who was a decision maker and had authority to negotiate a settlement.  I also asked to have them communicate with me through email.  I was told that communicating through email was not possible.  These calls followed the same pattern of hold-talk-transfer averaging 30 minutes each.  I repeated myself to 3 or 4 people who wrote down my complaint before I got to a manager who had decision making authority.  The manager denied any responsibility for the amount of time it took to arrange the service call and would not authorize a service credit.  
    The second issue involved billing.  I signed up for auto-pay to have my monthly bill deducted directly from my bank account.  Verizon’s computer system deducted the bill twice, overdrawing my account.  I incurred a bank overcharge fee.   The same pattern of hold-talk-transfer began for this complaint as well.  The customer service staff refused to take responsibility for this error as well.  Their solution required me to spend more time and incur extra expenses.  I had to repeat myself to 3 or 4 complaint takers before I reached the same manager who denied my first request.  He denied any responsibility for this billing problem too.    I had to have my bank retrieve the money under a fraud compliant.
    Verizon is one of the largest *communications* corporations in the world.  If your internal systems can't handle customer service calls in a reasonable amount of time, then there is a problem.  If your customer service staff is unwilling to take responsibility for such inadequacies and solve the issues that emerge from them, then there is a problem.  If a customer has to contact the CEO of the company to try to resolve two service related issues, then there is a problem.  When all of those actions prove inadequate, then there is a *communications* problem.
    Customer service has flagged my account and put me down as a “problem” customer.  Instead of offering even a token settlement, they are prepared to stonewall me by maintaining that the company is just not at fault and that they tried to solve the problems but I wouldn’t cooperate or accept their solutions.   Early on in the process, if someone told me that Verizon messed up just a little, but still couldn’t compensate me, I would have accepted that, albeit reluctantly, and dropped the matter.
    This is not the way I do business and I resent it when others don’t feel the need to honor any kind of code.  I grew up working in my family’s retail liquor store.  From the time I was a kid I learned four customer service lessons that I’ve carried over into my adult life:
    Admit when you are wrong and try to make up for the mistake.
    Never argue with a customer over small things.
    Listen to the compliant and don’t just dismiss it out-of-hand
    Try to make things right even though you may not be directly responsible for problem.
    For my two problems, Verizon customer service staff didn’t even come close to following these common sense rules.   I’ve learned that if you ask their customer service people they will repeat back to you some type of business code that they say they operate under.  But their behavior tells a different story.
    Unfortunately when I spoke with {edited for privacy} of the Executive Presidential Appeals office, I was taken somewhat aback by his manner and demeanor, which was coarse and inappropriate for a customer service discussion, and which I found personally offensive.  He and members of his staff agreed to send me emails specifying which part of the Terms of Service they based their decisions on.  To date I have not received the communications they promised.
    Is this the image of your company that you want the public to see? Are you willing to just shrug off these complaints as an isolated case that is too small to concern yourself about?  I’m afraid the answer will be yes.  Not only do you feel that you are too big to fail, but you are too big to care.   Customer service means solving problems not manufacturing bad will and resentment.  
    My purpose in writing this note has been twofold: to make one last effort to solve my problem and to hope that someone will take note about the issues about customer service practices that are harmful to the company. I'd be happy to speak with someone with real authority to deal
    with my issues but have no interest in repeating my past experiences.
    It's too bad that this had to happen since the solution could have been so easy and simple.
    I plan to publish some form of this letter and distribute it to the public. 
    Solved!
    Go to Solution.

    Therefore, I request to please clear this unacceptable due balance, and contact Experian to removed and clarified the mistake in my credit report. 
    RE:  Cancellation fee charged on internet DSL service charged by mistake. {edited for privacy}
    A $65 balance remain for a cancellation fee on internet DSL service, by Verizon New York mistake.
    In February of 2010, I set up my phone and TV in a vacation plan but keep my internet service active. After a month I had a vacation plan, suddenly without notification, my internet service was suspended and a cancellation fee was issued.
    My final statement was $ 24.47. I cleared a check from Verizon.
    I contacted Verizon online to request connect my internet service and discuss the issue on the cancellation fee. The response was that I should pay the internet cancellation fee, and paid a new activation.
    After fighting with Verizon customer service over the unacceptable fee charge service issue without any possibility of resolution I cancel my home phone which was in a vacation plan. 
     Later I kept receiving the statement with this cancellation fee every month. I called and discussed the issue more than 6 times during the next 6 months, The entire process kept me on the phone for a total of 2 hours over several months. The costumer representatives responded that the issue was in an investigation.
    Later,  a Collector company start chasing me to get the $65 paid. Phone number: {edited for privacy}, Inclusive, they made an offer to reduce the amount if I accept to pay or contact Verizon to request a clarification.
    By the end of the year, I contacted Verizon costumer services one more time but the representative stated that the account is not visible anymore.
    Convinced that the problem on this account was resolved, the second week of November, I called Verizon to reestablish my account with a new home phone number and Internet DSL connection.
    The answer was that  following Verizon policy I was unable to get a new account if a balance remain.
    After I explained the events, a manager (non-identified) who spoke to me by phone told me that Verizon will investigate the issue and I should wait for approval.
    On November 16, my account was confirmed approved and clear of debt, therefore, Verizon welcome me back with Home phone and internet DSL Service and confirmation on my online registration.
    New number:{edited for privacy} ; Email:{edited for privacy}
    Also, during the months of January and February 2010, Verizon New York, made other charges mistakes in my account (See details below) that have been resolved with an apologize and a refund.
    Events that prove the lack of training and support Verizon customer and billing service have.
    Chronology of the emails exchanged between Verizon Ecenter and myself after I requested investigation with the charges.
    01/10/10   I have contacted Verizon customer support regarding of a mistake in my internet service statement.Tracking # 430824. Reference: Duplicate charges for Internet Security suites service.
    1/12/10 Verizon eCenter responded. Angela. ' Apologized for the inconvenience. 'The cancellation and credit will appear on the next bill'.
    2/08/10 Verizon eCenter responded. Cheniqua. 'I have issued a credit of $6.52 for a Verizon internet security suite charges'; your internet charges
    2/04/10 I have contacted Verizon customer support in regard of clarification in my Direct TV  statement.
    Tracking # {edited for privacy}. Reference: Balance from Direct TV due to my recently requesting vacation plan.
    2/06/10 Verizon eCenter responded (John) Verizon Bill statement: February 26 = $6,73 paid
    2/06/10 I have contacted Verizon customer support in regard of a mistake in my home phone statement.
    Reference: By mistake, international fee in my home phone (inactive line/vacation plan) was charged.
    Tracking # {edited for privacy}
    2/08/10 Verizon eCenter responded. (Linnette) 'I apologize for the error'. 
    A credit for the international plan has been applied to your account and will appear on the next statement.'
    2/08/10 Verizon eCenter responded (Cheniqua) 'The regional essential calling plan does not qualify for a discount during vacation suspension. Which prove that my home phone was in a vacation plan.
     2/15/10 I have contacted Verizon customer support in regard of a non-notified, neither requested suddenly suspension on my internet DSL service and charged a cancellation fee for this suspension.
    Tracking # {edited for privacy}
    2/16/10 Verizon eCenter responded (Michael)  I am sorry for the inconvenience you have experienced. 
    Please contact our Consumer Sales and Solutions Center directly at 1-800-Verizon or (800) 837-4966 
    Monday through Friday between 8:00 AM to 6:00 PM Local Time. 
    2/16/10 Verizon eCenter (Sue)  responded : I am sorry for the inconvenience you have experienced. 
    I understand your frustration and concern regarding canceling your internet service in error. In order to provide you with the best customer service, please contact our Consumer DSL Sales and Solutions department directly at (800) 567-6789 and a representative will be happy to assist you.
    I stand on my decision of not pay for someone else mistakes.
    Your actions have damaged my integrity as a good costumer and citizenship.
    Without doubt after this problem get clearly resolved, you will lose this good costumer, get a negative feedback and I am planning to publish this letter at every web forum available.

  • Performance decrease with custom cell renderer

    Hi,
    Finally, I have my cell renderer working fine (it was simpler than I thought). Anyway, I'm suspecting something is not working quite well yet. When I try to reorder my colums (by dragging them) they move like slow motion. If I don't register my custom cell renderer, I can move my columns fine. Next is the code of my custom renderer.
    class PriorityRenderer extends DefaultTableCellRenderer {   
      public Component getTableCellRendererComponent(
      JTable table, Object value,     boolean isSelected,
      boolean hasFocus, int row, int column) {              
        if(value instanceof coloredValue) {
        coloredValue cv = (coloredValue)value;
        if(isSelected) this.setBackground(table.getSelectionBackground());
        else this.setBackground(cv.getbkColor());
        this.setForeground(cv.gettxColor());
        this.setText(value.toString());
        this.setOpaque(true);
        return this;
    }All the cells of my JTable are "coloredValue"s. This is a little class with a String, two colors and some getter methods.
    Can anyone giveme a hint ?
    Thanks!!

    OK! Now the performance problem is gone!! (I don't know why, I didn't touch a thing)
    Thanks anyway

  • JTable & custom cell editor

    Hello everyone,
    what is the correct way of writing a custom cell editor for a JTable? I followed the example in the Java tutorial ([How to use tables|http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#editor]), but the result is a bit weird. The code I have is the following:
        private class NumericCellEditor extends AbstractCellEditor implements TableCellEditor {
            NumericFTField field = new NumericFTField(threeDecimalsFormat, 3, null, 1);
            public Component getTableCellEditorComponent(JTable table, Object value,
                    boolean isSelected, int row, int col) {
                field.setValue(value);
                return field;
            public Object getCellEditorValue() {
                return field.getValue();
            @Override
            public boolean stopCellEditing() {
                if (((NumericFTField)field).verifyDouble()) {
                    field.setBorder(new EmptyBorder(0, 0, 0, 0));
                    fireEditingStopped();
                    return true;
                } else {
                    field.setBorder(BorderFactory.createLineBorder(Color.red));
                    return false;
        }where the NumericFTField is a class derived from JFormattedTextField that only allows digits, decimal separator, minus and 'E' to be inserted, and it monitors clipboard operations. verifyDouble() is a method of the NumericFTField class that verifies whether the current input can be parsed to a double and whether it satisfies everything it should. This is then used in
    ((TableColumn)jTblSpecs.getColumnModel().getColumn(1)).setCellEditor(new NumericCellEditor());The NumericFTField class works great, I use it also in place of a JTextFields, so I'd say there is nothing wrong with it.
    After I click in a cell (single click), it behaves a little different that the default cell editor: the cell is not highlighted, but it immediately jumps to the editing state (why???). I, indeed, can insert the allowed characters only. When I click in a cell, do some editing and press Enter, the cell's content gets validated. If it is invalid, stopCellEditing() method does its magic; if it is valid, the caret disappears and everything SEEMS okay. However, if I started typing at this point, the cell reverts to the editing state, but now I am able to enter any character I want. It truly looks like the cell editor is now some other component, not the original NumericFTField one. What is going on here?
    It would be great is someone could provide a short schematic source of a custom cell editor class that would work exactly as the JTable's default one except it would only permit digits and so on. It doesn't have to be anything fancy, just a "skeleton" of the class with comments like "input verification here" etc.
    I am sorry for any lack of clarity, but I am still a Java newbie.
    Any help would be much appreciated.
    Best regards,
    vt

    Hi,
    I am also facing the same problem. In addition to what you have specified, my requirement is to be able to select multiple rows for deletion. But, the very first row selected using mouse is not visible as selected though its selected. The other rows are visible as selected.
    If you can use any JDK version, start using JDK1.6. You will not be facing this problem. There were so many changes done for swings from JDK 1.4 to 1.6. But, I have to strictly use JDK1.4, but could not find any workaround for this problem.
    It would be great if anyone can help me out in this issue to get workaround for this problem.

  • JTable custom cell editor losing focus

    This is a followup to Re: Tutorial on AWT/Swing control flow wherein I ask for pointers to help me understand the source of focus-loss behaviour in my JTable's custom cell editor.
    I have done some more investigations and it turns out that the focus loss is a more general problem with custom cell editors which call other windows. Even the color-picker demo in the JTable tutorial at http://download.oracle.com/javase/tutorial/uiswing/examples/components/index.html#TableDialogEditDemo has this problem, IF you add a text field or two to the layout BEFORE the table. The only reason the table in the demo doesn't lose the focus when the color-picker comes out is because the table is the only thing in the window!
    Here is the demo code, augmented with two text fields, which are admittedly ugly here but which serve the desired purpose:
    * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *   - Redistributions of source code must retain the above copyright
    *     notice, this list of conditions and the following disclaimer.
    *   - Redistributions in binary form must reproduce the above copyright
    *     notice, this list of conditions and the following disclaimer in the
    *     documentation and/or other materials provided with the distribution.
    *   - Neither the name of Oracle or the names of its
    *     contributors may be used to endorse or promote products derived
    *     from this software without specific prior written permission.
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    import javax.swing.*;
    import javax.swing.border.Border;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableCellRenderer;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class TableDialogEditDemo extends JPanel {
        public class ColorEditor extends AbstractCellEditor
                implements TableCellEditor,
                ActionListener {
            Color currentColor;
            JButton button;
            JColorChooser colorChooser;
            JDialog dialog;
            protected static final String EDIT = "edit";
            public ColorEditor() {
                //Set up the editor (from the table's point of view), which is a button.
                //This button brings up the color chooser dialog, which is the editor from the user's point of view.
                button = new JButton();
                button.setActionCommand(EDIT);
                button.addActionListener(this);
                button.setBorderPainted(false);
                //Set up the dialog that the button brings up.
                colorChooser = new JColorChooser();
                dialog = JColorChooser.createDialog(button, "Pick a Color", true,  //modal
                        colorChooser, this,  //OK button handler
                        null); //no CANCEL button handler
             * Handles events from the editor button and from the dialog's OK button.
            public void actionPerformed(ActionEvent e) {
                if (EDIT.equals(e.getActionCommand())) {
                    //The user has clicked the cell, so bring up the dialog.
                    button.setBackground(currentColor);
                    colorChooser.setColor(currentColor);
                    dialog.setVisible(true);
                    //Make the renderer reappear.
                    fireEditingStopped();
                } else { //User pressed dialog's "OK" button
                    currentColor = colorChooser.getColor();
            public Object getCellEditorValue() {
                return currentColor;
            public Component getTableCellEditorComponent(JTable table,
                                                         Object value,
                                                         boolean isSelected,
                                                         int row,
                                                         int column) {
                currentColor = (Color) value;
                return button;
        public class ColorRenderer extends JLabel
                implements TableCellRenderer {
            Border unselectedBorder = null;
            Border selectedBorder = null;
            boolean isBordered = true;
            public ColorRenderer(boolean isBordered) {
                this.isBordered = isBordered;
                setOpaque(true);
            public Component getTableCellRendererComponent(
                    JTable table, Object color,
                    boolean isSelected, boolean hasFocus,
                    int row, int column) {
                Color newColor = (Color) color;
                setBackground(newColor);
                if (isBordered) {
                    if (isSelected) {
                        if (selectedBorder == null) {
                            selectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
                                    table.getSelectionBackground());
                        setBorder(selectedBorder);
                    } else {
                        if (unselectedBorder == null) {
                            unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
                                    table.getBackground());
                        setBorder(unselectedBorder);
                return this;
        public TableDialogEditDemo() {
            super(new GridLayout());
            JTextField tf1 = new JTextField("tf1");
            add(tf1);
            JTextField tf2 = new JTextField("tf2");
            add(tf2);
            JTable table = new JTable(new MyTableModel());
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            table.setFillsViewportHeight(true);
            JScrollPane scrollPane = new JScrollPane(table);
            table.setDefaultRenderer(Color.class,
                    new ColorRenderer(true));
            table.setDefaultEditor(Color.class,
                    new ColorEditor());
            add(scrollPane);
        class MyTableModel extends AbstractTableModel {
            private String[] columnNames = {"First Name",
                    "Favorite Color",
                    "Sport",
                    "# of Years",
                    "Vegetarian"};
            private Object[][] data = {
                    {"Mary", new Color(153, 0, 153),
                            "Snowboarding", new Integer(5), new Boolean(false)},
                    {"Alison", new Color(51, 51, 153),
                            "Rowing", new Integer(3), new Boolean(true)},
                    {"Kathy", new Color(51, 102, 51),
                            "Knitting", new Integer(2), new Boolean(false)},
                    {"Sharon", Color.red,
                            "Speed reading", new Integer(20), new Boolean(true)},
                    {"Philip", Color.pink,
                            "Pool", new Integer(10), new Boolean(false)}
            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 boolean isCellEditable(int row, int col) {
                if (col < 1) {
                    return false;
                } else {
                    return true;
            public void setValueAt(Object value, int row, int col) {
                data[row][col] = value;
                fireTableCellUpdated(row, col);
        private static void createAndShowGUI() {
            JFrame frame = new JFrame("TableDialogEditDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JComponent newContentPane = new TableDialogEditDemo();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }When you come back from choosing a color, tf1 is given the focus, instead of the table. This is because bringing the color picker window to the front causes a focus lost event for the cell editor component; it's temporary, as it should be, so why on earth is the system losing track of who has focus in the window??
    I see the following in Window#getMostRecentFocusOwner():
      public Component getMostRecentFocusOwner()
        if (isFocused())
          return getFocusOwner();
        else
          Component mostRecent =
            KeyboardFocusManager.getMostRecentFocusOwner(this);
          if (mostRecent != null)
            return mostRecent;
          else
            return (isFocusableWindow())
                   ? getFocusTraversalPolicy().getInitialComponent(this)
                   : null;
      }My app has a custom focus traversal policy, so I'm able to see who is being called, and indeed, getInitialComponent() is being called. Clearly, the KeyboardFocusManager is actually losing track of the fact that the table was focussed at the point where control was transferred to the color picker! This strikes me as completely unreasonable, especially since, as noted, this is a temporary focus loss event, not a permanent one.
    I'd be grateful for any wisdom in solving this, since similar behaviour to this little demo -- without focus loss, naturally -- is an essential part of my application.

    Looks like it is because the 'restore-focus-to-previous-after-modal-dialog-close' is in a later event than when the control returns to the action performed (which I guess makes sense: it continues the action event handler and the focus events are handled later, but I needed two chained invoke laters so it might also be that the OS events comes later).
    The following works for me (in the actionPerformed edited):
               // create the dialog here so it is correctly parented
               // (otherwise sometimes OK button not correctly the default button)
               dialog = JColorChooser.createDialog(button, "Pick a Color", true,  //modal
                            colorChooser, this,  //OK button handler
                            null); //no CANCEL button handler
                    //The user has clicked the cell, so bring up the dialog.
                    button.setBackground(currentColor);
                    colorChooser.setColor(currentColor);
                    button.addFocusListener(new FocusListener() {
                        @Override
                        public void focusLost(FocusEvent e) {}
                        @Override
                        public void focusGained(FocusEvent e) {
                            // dialog closed and focus restored
                            button.removeFocusListener(this);
                            fireEditingStopped();
                    dialog.setVisible(true);but a simpler request might be better (althoug I still need an invoke later):
    // rest as before except the FocusListener
                    dialog.setVisible(true);
                    button.requestFocusInWindow();
                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            fireEditingStopped();
                    });And a quick fix to the renderer so you can actualy see the focus on it:
                    if(hasFocus) {
                        Border border = DefaultLookup.getBorder(this, ui, "Table.focusCellHighlightBorder");
                        setBorder(BorderFactory.createCompoundBorder(
                                border, BorderFactory.createMatteBorder(1, 4, 1, 4,
                                        ((MatteBorder) getBorder()).getMatteColor())));
                    }

  • JTable - Custom cell editor lossing commit

    Hello,
    I have a custom cell editor and a default renderer assigned to a specific cell in my table...
    I have the following problem :
    If i change the value of cell 'c1' from value 'v1' to 'v2' and press enter and go to another cell the value in 'c1' is rendered correctly as 'v2'
    Hoever if i change the value of cell 'c1' from 'v1' to 'v2' and simply click over to another cell the value in 'c1' stays rendered as 'v1'
    Question : Is there ANY way to mimic the behavior of the user pressing enter in my custom cell editor when a user simply selects another cell, i guess on loss of focus or something..
    This is the last problem i have on the current project i am on and its very annoying.
    Thanks in advance, any help appreciated..
    -Alan

    I have the same problem using a custom Date/Time Picker Object (which extends JComboBox) as an editor within a table cell. For simplicity sake, I am posting code using only the base editable JComboBox, but it exhibits the same symptoms. If you enter a value in the TextField portion of the ComboBox and Tab, your value remains the same. If you enter a value in the TextField portion of the ComboBox and click in another cell, the value returns to the previous value (before editing began).
    import java.awt.*;                                                  // BorderLayout
    import javax.swing.*;                                               // JTable, JFrame
    import javax.swing.table.*;                                         // DefaultTableModel
    public class Tester extends JFrame
      public static void main(String[] args)
        Tester test = new Tester();
      public Tester()
        String[] values = {"Test", "Values"};
        JComboBox combo = new JComboBox(values);
        combo.setEditable(true);
        DefaultCellEditor editor = new DefaultCellEditor(combo);
        JTable table = new JTable(2, 3);
        table.getColumn(table.getColumnName(0)).setCellEditor(editor);
        JScrollPane scroll = new JScrollPane(table);
        getContentPane().add(scroll, BorderLayout.CENTER);
        pack();
        setVisible(true);
    }

  • Custom Cell Renderer / Video garbage on "refresh"

    I have created a custom Cell Renderer for my JTable. When the application in which this JTable is displayed, is moved into the background and then brought back "front", The application does not redraw itself completely.
    I am able to see the information contained in the JTable but none of the surrounding components. When I do a mouse click on any of the background of the surrounding panel, nothing happens.
    In order to get the entire Panel/View/all visible components to refresh themselves, I have to click on aother component (example would be switching to a different panel of the tabbed pane.)
    This only happens when I have a JTable with this particular Renderer showing. Any other panel or JTable not using this Renderer refreshes completely.
    Here is my Cell Renderer most of which I borrowed extensively from info posted in these forums:
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.io.*;
    * This is a much lighter version of the multiline renderer.  It does need to have newline
    * characters at the points where the next line should occur.
    public class CTAuditTableCellRenderer extends JList implements TableCellRenderer {
        public CTAuditTableCellRenderer() {
            setOpaque(true);
            ListCellRenderer renderer = getCellRenderer();
            ((JLabel)renderer).setHorizontalAlignment(JLabel.CENTER);
            setCellRenderer(renderer);
        *   getTableCellRendererComponent() is the only method that must be over-ridden.
        *   @param table the JTable holding cell we wish to render
        *   @param value the object which we wish to put into the cell
        *   @param isSelected boolean to allow selected cell to appear as such
        *   @param hasFocus boolean to alert as to the cell having focus
        *   @param row row of the JTable in which cell resides
        *   @param column column of the JTable in which the cell resides.
        *   @return Component the image of the value object.  Not a true object but an
        *   image of the object.
        public Component getTableCellRendererComponent(JTable table, Object value,
                                    boolean isSelected, boolean hasFocus, int row, int column) {
            if (isSelected) {
                setForeground(table.getSelectionForeground());
                setBackground(table.getSelectionBackground());
            } else {
                setForeground(table.getForeground());
                setBackground(table.getBackground());
            setFont(table.getFont());
            if (hasFocus) {
                setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
                if (table.isCellEditable(row, column)) {
                    setForeground( UIManager.getColor("Table.focusCellForeground") );
                    setBackground( UIManager.getColor("Table.focusCellBackground") );
            } else {
                setBorder(new EmptyBorder(1, 2, 1, 2));
            String str = (value == null) ? "" : value.toString();
            BufferedReader br = new BufferedReader(new StringReader(str));
            String line;
            Vector v = new Vector();
            try {
                while ((line = br.readLine()) != null) {
                    v.addElement(line);
            } catch (IOException ex) { ex.printStackTrace(); }
            setListData(v);
            if(v.size() > 1){
                table.setRowHeight(row, (table.getRowHeight()+ 3)* v.size());
            return this;
    }Thank you in advance for your constructive, insightful, and applicable replies.
    Jerry

    Here is an entire example that shows the situation of the Frame (in this case) not updating/refreshing all of it's components when regaining focus.
    To simulate the problem, simply move "something"/another window over the sample frame and then move it off. In my case the scrollbar and the headers do not reappear until I have selected a row and scrolled the table.
    Here is the example code:
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MultiLineCellExample extends JFrame {
      MultiLineCellExample() {
        super( "Multi-Line Cell Example" );
        DefaultTableModel dm = new DefaultTableModel() {
          public Class getColumnClass(int columnIndex) {
            return String.class;
        dm.setDataVector(new Object[][]{{"aa aa aa aa aa\naa aa aa aa aa\naa aa aa aa aa","b","c"},
                                        {"A","B","C\nC"},{"x","y","z"}},
                         new Object[]{"1","2","3"});
        JTable table = new JTable( dm );
        table.setDefaultRenderer(String.class, new MultiLineCellRenderer());
        JScrollPane scroll = new JScrollPane( table );
        getContentPane().add( scroll );
        setSize( 400, 130 );
        setVisible(true);
      public static void main(String[] args) {
        MultiLineCellExample frame = new MultiLineCellExample();
        frame.addWindowListener( new WindowAdapter() {
          public void windowClosing( WindowEvent e ) {
            System.exit(0);
    }And here is the Renderer code:
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.io.*;
    public class MultiLineCellRenderer extends JList implements TableCellRenderer {
        public MultiLineCellRenderer() {
            setOpaque(true);
            ListCellRenderer renderer = getCellRenderer();
            ((JLabel)renderer).setHorizontalAlignment(JLabel.CENTER);
            setCellRenderer(renderer);
        public Component getTableCellRendererComponent(JTable table, Object value,
                                    boolean isSelected, boolean hasFocus, int row, int column) {
            if (isSelected) {
                setForeground(table.getSelectionForeground());
                setBackground(table.getSelectionBackground());
            } else {
                setForeground(table.getForeground());
                setBackground(table.getBackground());
            setFont(table.getFont());
            if (hasFocus) {
                setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
                if (table.isCellEditable(row, column)) {
                    setForeground( UIManager.getColor("Table.focusCellForeground") );
                    setBackground( UIManager.getColor("Table.focusCellBackground") );
            } else {
                setBorder(new EmptyBorder(0, 0, 0, 0));
            String str = (value == null) ? "" : value.toString();
            BufferedReader br = new BufferedReader(new StringReader(str));
            String line;
            Vector v = new Vector();
            try {
                while ((line = br.readLine()) != null) {
                    v.addElement(line);
            } catch (IOException ex) { ex.printStackTrace(); }
            setListData(v);
            if(v.size() > 1){
                table.setRowHeight(row, (table.getRowHeight()+2)* v.size());
            return this;
    }Please, this is a very annoying problem and I would appreciate help in solving.
    Jerry

  • Custom Cell Renderer and JTable

    Hello all,
    here is what i am trying to do. i want that when a user clicks on a cell the
    color of the cell should change to say red. when the user clicks on the other
    cell the red color in the first cell should remain.
    the way i am trying do to this is by making an object which contains an on and
    off state. based on click ie valuechanged() method in table
    based on the row and column i change the value of the boolean state on. my
    custom cell renderer checks whether the state is on or off
    and then changes the color.
    rightnow I am able to change the color on click but am unable to retain the
    color. so how can i retain the color.
    // making table
              vectorForSingleRow.add(0, "");                    
              vectorForSingleRow.add(1, new CellColorObject(TEXT_EDITOR));     
              Vector tempVectorForSingleRow = new Vector(vectorForSingleRow);               
              tempVectorForSingleRow.set(0, name);     
              vectorForSingleRow.set(1, new CellColorObject(TEXT_EDITOR));          
              data.add( tempVectorForSingleRow ); // data is a vector
              myTableModel = new DefaultTableModel(data, columnNames)
              //Customrenderer
              public Component getTableCellRendererComponent(JTable table, Object value,      
                                                     boolean isSelected, boolean hasFocus, int row, int column) {
              CellColorObject myObj = (CellColorObject)value;
              this.setText(value.toString());
                   System.out.println("value.getClickedStatus() " + myObj.getClickedState());
                   if(myObj.getClickedState()){
                        System.out.println("in 2");     
                        this.setBackground(Color.PINK);
                   if(isSelected){
                   System.out.println("in 1");
                   this.setSelected(true);
    // other things and end of method
    //custom object for storing state of the cell                                   
    public class CellColorObject{
         private String name = "";
         private boolean clickedState = false;
         public CellColorObject(String incomingName){
              name = incomingName;
         public void setClickedState(boolean newClickedState){
         System.out.println("setClickedState");
              clickedState = newClickedState;
         public boolean getClickedState(){
         System.out.println("getClickedState()");
              return clickedState;
         public String toString(){
              return name;
    // valueChanged method
           public void valueChanged(ListSelectionEvent e) {
             if (e.getValueIsAdjusting()) return;
              if(column == 1){
                   CellColorObject tempObj = (CellColorObject) myTable.getValueAt(row,column);
                   tempObj.setClickedState(true);
                   myTable.setValueAt(tempObj, row, column);
    // other things and method end
              

    You problem is that you are NOT setting the clickedState of your object:
    public Component getTableCellRendererComponent(JTable table, Object value,                                                       boolean isSelected, boolean hasFocus, int row, int column) {                         CellColorObject myObj = (CellColorObject)value;          this.setText(value.toString());                         System.out.println("value.getClickedStatus() " + myObj.getClickedState());               if(myObj.getClickedState()){                    System.out.println("in 2");                         this.setBackground(Color.PINK);               }               if(isSelected){               System.out.println("in 1");               this.setSelected(true);In the above, you have
    if (myObject.getClickedState())
    /// do code..
    notice you have:
    if (isSelected)
    this.setSelected(true);
    Maybe I am missing something, but I see no code that sets your objects clicked state when selected. My guess is that you should be doing value.setClickedState(true) when the thing is selected, something like:
    CellColorObject myObj = (CellColorObject)value;
    if (isSelected)
    myObj.setClickedState(true);
    else
    myObj.setClickedState(false);
    BUT, you didn't finish your code snippet within the method there, so perhaps you do this already?
    What you have should almost work, in that every single cell will call this method and if the object's clickedState is true, it should set the background color. Just make sure you are setting the objects clicked state.

  • Overriding double click in JTable custom cell

    I have a JTable where I reset the custom cells to become editable on a single click instead if a double using:
    ((DefaultCellEditor)table.getDefaultEditor(String.class)).setClickCountToStart(1);
    Now what I need to do is display a JPopupMenu click a cell is double clicked. This works on cells that are not editable but the problem is that the user needs the popup dialog to display info for the cells that are editable.
    I have used the basic way to implement a double click on a certain column (in this case my third column):
    public void mouseClicked(MouseEvent e){
                   if (e.getClickCount() == 2 && table.getSelectedColumn() == 2 ){
                        popupMenu.show( e.getComponent(),
    e.getX(), e.getY() );
    But when double clicking, nothing happens.
    Anyone have any idea to implement this or over-ride an editable cell?
    Thanks,
    Chris

    This still says <identifier> expect, how can I resove this please? Then you still have something wrong with your code. Since you didn't post your code how are we supposed to help?
    The proper way to ask a question is to include your demo code that trys to illustrate the problem. Something like the following:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TableRightClick extends JFrame
         public TableRightClick()
              JTable table = new JTable(10, 5);
              table.addMouseListener( new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        if ( SwingUtilities.isRightMouseButton(e) )
    //                    if (e.isPopupTrigger())
                             JTable source = (JTable)e.getSource();
                             int row = source.rowAtPoint( e.getPoint() );
                             int column = source.columnAtPoint( e.getPoint() );
                             System.out.println(column);
                             source.changeSelection(row, column, false, false);
              table.setPreferredScrollableViewportSize(table.getPreferredSize());
              getContentPane().add( new JScrollPane(table) );
         public static void main(String[] args)
              TableRightClick frame = new TableRightClick();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );
    }

Maybe you are looking for

  • Why can't I open an InDesign file on a computer that only has Creative Suite (no cloud)?

    I have one computer with the cloud. One computer with the whole suite. When I try to open a document on my computer with the suite that I had previously saved from my computer with the cloud - I receive an error message. Why is this happening and how

  • Montior

    Is it possible to connect an sun server (E450 in this case) directly to a pc monitor? Are adapters needed or do you need software on the windows pc? Thanks in advance

  • Check number OverFlowing

    Hi Guys, I am facing some problem while doing check printing . We are printing Checks thru Check Printing from Checks for Payment window and we are using check stock and we are entering the check number manuallly  while adding payments. so when we pr

  • Can't use the knife tool to cut the rounded rectangle

    The knife tool is grayed out when I try to use it ona rounded rectangle. How can I errase part of a rounded rectangle?

  • Problem Re-installing CS6 on a Mac.

    I'm running OS 10.9.4 on a MacBook Pro and had to re-install the OS yesterday because something became corrupt. When launching an Adobe CS application, I get an error message that says to uninstall and then re-install the applications. Now that I am