Start or stop edit jtable cell editing

Hello,
I got a problem with the jtable DefaultModel isCellEditable.
If I set the IsCellEditable to false, I would not be able to enable the cell selection as and when I want it.
What I have in mind is the add a mouselister so that if the user select a row using fast left mouse click like the procedure shown below
private class MouseClickHandler extends MouseAdapter {
public void mouseClicked(MouseEvent event) {
int no_mouseclick = 0;
no_mouseclick = event.getClickCount();
if (no_mouseclick >= 2) {
int cur_row = 0;
cur_row = table.getSelectedRow();
// table.setColumnSelectionAllowed(true);
// table.setRowSelectionAllowed(true);
for (int i=0;i<table.getColumnCount();i++){
table.editCellAt(cur_row,i);
System.out.println("mouse row--->" + cur_row);
I could overwrite the IsCellEditable to true to enable that particular or cell contains in that row to be able to accept input and overwrite any data which in my case obtained from the Sql database a sort of like input module using tabulation . I am also thinking of using text component or combobox to display the value for user selection , but I do not know how to enable a particular cell for editing if the Jtable created is using a non-editable DefaultModel. If I set the IsCellEditable to true, every single cell would be enable for editing , and this defeat the purpose of enable user input only upon double mouseclicks.
By the way , I am interested to know how to track the data changes in the cell within the jtable so that only those have been modified are notify from the Table model and updated into the Sql table
Could anyone of you out there provide some hints please
Thanks

Hello,
Tablemodellistener could detect the changes in the data, how about the backend database updating and transactional activity that must be associated with the data changes?
What is on my mind is that , the moment there is changes in the data detected by the TableModellistener, whatever records associated with or brougt up by Jtable would be all deleted from the database and then follow by the new set of new records to be inserted into the database. The disadvantage of this method is that everytime the backend database connection and activity need to be executed the moment there is a change in the data in the jtable cell. For example the user may be just amendment to only one cell , but all the records associated need to be deleted and then inserted again.
Perhaps there are better solution to deal with Jtable and JDBC backend connection where in this case, I am using JDO to undertake the database activity like the observable modelling .
Could someone provide the hint please
Thank

Similar Messages

  • Dynamically Rendering and editing JTable cell

    Hi all,
    I wonder if some body can help me.
    As in my application each cell in Jtable returns java Object. and what i am trying to do is based on each object returned in cell my renderer is going to change dynamically. for example if the object returned is primitive data types the renderer is defualt, if the returned object is Map, Set or List, then the Cell Renderer should show clickable button with icon on right hand side and TextField on left hand side and so on for other objects. i am able get renderer for Map, set or list, which is button on right hand side of cell and text field on left hand side displaying toString of Object. then what i want is when i click button it should show those values in popup window and if i double click it should edit the cell which i am able to do it. so how can i handle events or what i have to do to make button clickable. if any body come accross these situations or got idea. please let me know how to move further.
    Thanks,
    Kotesh.

    Hi,
    Thanks for your advise and as i said i am able to get render for Map as (TextField in left hand side+Button with icon in right hand side side) of Cell. but what i need is when i click button which is on right hand, then i should be able to show popup wvindow with map values and if i double click on TextField which is on right hand side, then i should be able to edit Cell which is happening. but i am not able to get popup window when i click button on right hand side of cell. basically i am not sure how to handle events on cell and the button on right hand side?
    if some one can guide me that will be great as i am in big trouble.
    Thanks
    Kotesh.

  • Non-editable JTable cells?

    Is there any way to make all the cells in a JTable non-editable? In the API I see the isEditable method, but no setEditable method. Any suggestions?

    You have to set it in the TableModel.
    TableModel model = new AbstractTableModel()
    public int getRowCount()
    return 10;
    public int getColumnCount()
    return 5;
    public Object getValueAt(int row, int column)
    return "( "+row+","+column+" )";
    public boolean isCellEditable(int row,int column)
    return false;
    The one given above is a sample to show you how to set a cell non-editable on the cell. You have to customize it for your table model.
    Thanks,
    Kalyan

  • Edit JTable Cell

    Hi,ALL
    I have create normal JTable.and set all cell Editable.
    When I double clike a cell, I can modify the value on the cell.
    However, When I use getValueAt(row, col)
    it still give me the orginal value, not the modified value!
    Do I lost something? Or do I need to implement something else?
    any idea would be greated appreciated

    It may also depend on when you're calling getValueAt. If you're doing it before the edit has committed to the table model (ie, before setValueAt has been called) then the underlying data won't yet have been updated.
    It would be useful if you could supply some example code for what you're trying to do (post it in [ code ] tags please!).
    Hope this helps.

  • Stop sorting after cell editing

    Is it possible to stop the TableSorter?
    when the sorting of a column is activated and after editing a cell of that column then exiting the cell, the table is sorted again refering to the new edited value and this is indesirable, I mean I want that sorting is done only whe I click on the header and when editing a cell the row containing this cell must still where it is even if the column is in sorting mode.
    I'm using sun tablesorter
    any one have an idea please?

    :) I just found it bymyself, i just removed the listener of trhe table model in tablesorter

  • Can you stop table indicator cell editing?

    Hello,
      Is there a way to disable the ability of a user to edit the cells of a table indicator? I have a table indicator on my front panel and just want it to be a indicator, nothing else. I have found that I can change the contents of a cell in the table indicator and type in any value I want. 
    Regards,
    Kaspar

    A technique I have used at times to quickly disable multiple controls at one time (provided they are located near each other) is to create a simple string indicator that is transparent. Size it so that it covers the controls (in your case the table) that you want to disable. In your code when you want to disable those controls use the property node to make the transparent string control visible. When you want to enable the controls use the property node to set the "visible" attribute to false. This is a simple trick that can be useful at times.
    Message Edited by Mark Yedinak on 02-17-2010 02:32 PM
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • JTable & Cell editing

    Hi,
    I am using JTable and facing following problem. My UI has a JTable and JButton with mnemonic set. The button populates the date into the table. Here is the sequence
    1) Enter into editing mode by pressing F2 and enter value EE
    2) I press the mnemonic set for button
    3) ActionListener attached to button is executed. This ActionListener populates the data into the table.
    4) The cell on which editing was started remains in the editing mode and the value for edited cell does not change to the populated by ActionListener but remains EE. (This is the problem)
    What i want is whenever focus moves out of the table if the table is in editing mode then it should cancel the editing.
    I tried attaching the focus listener but problem with this is focusLost is fired even when i press F2 i.e. start editing.
    Any help will be of great use
    Thanks in advance
    Sachin

    Hi,
    It works in normal scenaios. I faced problem in following
    1) My cell editor has a verifier attached. if i show a dialog box from verify method and then return false from method focus remains in cell only, this is fine.
    2) If i show the dialog and return true from verify method, table remains in editing mode and focus gets transferred to the field. This time i am navigating through mouse.
    3) In the same scenario (2) if i tab out of the field cell does not come out of edit mode i have to press tab to come out of the field.
    Any idea??
    Sachin

  • JTable cell edits return to original values

    Hi
    I am making some progress with using AbstractTableModel, however I have a problem whereby any edits that I make to cells within the table are being lost when I add a new row��the original values are re-appearing.
    I have searched through the forum looking for a solution but with no success thus far.
    I believe that the solution lies with the fireTableDataChanged() method but thus far I have had no success. My problem (I believe) is that I cannot work out how to fire it when a user leaves the newly edited cell.
    The method that adds the new rows is shown below and is called from a button on the Frame that houses the jTable. I have tried firing the method from here, hoping that all table edits will persist, but unfortunately they still disappear.
    public void fillTable()
            if(c > 0)
                for (int i = 0; i < c; i = i + 1)
                    this.setValueAt(((JobItemClass) items.get(i)).getItemNumber(), i, 0);
                    this.setValueAt(((JobItemClass) items.get(i)).getDescription(), i, 1);
                    this.setValueAt(((JobItemClass) items.get(i)).getCostPerItem(), i, 2);
                    this.setValueAt(((JobItemClass) items.get(i)).getQuantity(), i, 3);
        public void addRow()
            newItem = new JobItemClass();   //Create an object to hold the new row defsault values
            newItem.setItemNumber(c + 1);
            newItem.setDescription("");
            newItem.setCostPerItem(0.0);
            newItem.setQuantity(0);
            items.add(c, newItem);          //Add the default object to the array
            c = c + 1;                      //Update the variable holding the array size
            table = new Object[c][4];       //Increase the size of the object that acts as the table
            fireTableRowsInserted(c, c);    //Alert the object acting as the table that there is a new row
            fillTable();                    //Refresh the display to reflect the new row default values      
        }As always, any help greatly appreciated
    GB

    Thanks again for the replies people.
    I decided to edit this message and post updated code which can be seen below. This is a result of re-reading the helpfull advice from both azukov and camickr who took the time to respond to my initial request for help. I still have to work out how to validate user input but am sure that the tableChanged method will be the key.
    A simple tutorial also provided great assistance, especially helping eith the implementation of the TableModelListener. I have provided a link to the tutorial here:
    http://www.javalobby.org/articles/jtable/
    The coding was carried out in netbeans 5.5, libraries have not been included.
    Here is my updated code......table model first:
    public class MyJobItemTableModel extends AbstractTableModel
        JobItemClass newItem;   //Procides a default record when nothing available
        int jobNo;
        int c;
        ArrayList items;        //Stores the objects that provide the records
        public MyJobItemTableModel(int j)
            jobNo = j;
            items = (new JobAllItems(jobNo)).getItems();
            c = items.size();
        String columnName[] = { "Item Number", "Item Description", "Cost per item", "Quantity" };       
        Class columnType[] = { Integer.class, String.class, Double.class, Integer.class };
        /**************************This method probably now redundant************************
        public void storeCellValue(int row, int col)
            if(col == 0)
                ((JobItemClass) items.get(row)).setItemNumber((Integer) this.getValueAt(row, col));
            if(col == 1)
                ((JobItemClass) items.get(row)).setDescription((String) this.getValueAt(row, col));
            if(col == 2)
                ((JobItemClass) items.get(row)).setCostPerItem((Double) this.getValueAt(row, col));
            if(col == 3)
                ((JobItemClass) items.get(row)).setQuantity((Integer) this.getValueAt(row, col));
        public void addRow()
            c = c + 1;                          //Update the variable holding the array size
            newItem = new JobItemClass();       //Create a default object to fill the new row
            newItem.setItemNumber(c);
            newItem.setDescription("");
            newItem.setCostPerItem(0.0);
            newItem.setQuantity(0);
            items.add(c-1, newItem);
            this.fireTableRowsInserted(c, c);   //Update the display to show the added row.
        public int getColumnCount()
            return 4;
        public int getRowCount()
            return items.size();
        public Object getValueAt(int r, int c)
            JobItemClass jic = (JobItemClass) items.get(r);
            switch(c)
                case 0:
                    return jic.getItemNumber();
                case 1:
                    return jic.getDescription();
                case 2:
                    return jic.getCostPerItem();
                case 3:
                    return jic.getQuantity();
                default:
                    return new Object();               
        public String getColumnName(int column)
            return columnName[column];
        public Class getColumnClass(int c)
            return columnType[c];
        public boolean hasNoItems()
            if(items.size() == 0)
                return true;
            else
                return false;
        public boolean isCellEditable(int r, int c)
            return true;
        public void setValueAt(Object aValue, int r, int c)
            JobItemClass jic = (JobItemClass) items.get(r);
            switch(c)
                case 0:
                    jic.setItemNumber((Integer)aValue);
                    break;
                case 1:
                    jic.setDescription((String)aValue);
                    break;
                case 2:
                    jic.setCostPerItem((Double)aValue);
                    break;
                case 3:
                    jic.setQuantity((Integer)aValue);
                    break;              
            fireTableCellUpdated(r, c);
    }......and now the view (what the user sees)
    public class ViewItems extends javax.swing.JPanel
        protected MyJobItemTableModel myModel;
        /** Creates new form ViewItems */
        public ViewItems()
            initComponents();
        public void createTable(int jobNo)
            myModel = new MyJobItemTableModel(jobNo);
            myModel.addTableModelListener(new ViewItems.ViewItemsTableModelListener());
            jTable1.setModel(myModel);
            //jTable1.setSurrendersFocusOnKeystroke(true);  //not sure what this does
            if (myModel.hasNoItems())
                myModel.addRow();          
            public void run(int jobNo)
                createTable(jobNo);
                try
                    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                    JFrame frame = new JFrame("Invoice Breakdown");
                    frame.addWindowListener(new WindowAdapter()
                        public void windowClosing(WindowEvent evt)
                            setVisible(false);
                    frame.getContentPane().add(this);
                    frame.pack();
                    frame.setVisible(true);
                catch (Exception e)
                    e.printStackTrace();
            /**This class is required in order to respond to any changes that happen
             * to the table or data within, i.e. the user editing data in a cell.
             * The tablemodel (MyJobItemTableModel) will 'fire' the event and the
             * tableChanged() method will be executed.
            public class ViewItemsTableModelListener implements TableModelListener
                public void tableChanged(TableModelEvent evt)
                    if (evt.getType() == TableModelEvent.UPDATE)
                        int column = evt.getColumn();
                        int row = evt.getFirstRow();
                        System.out.println("row: " + row + " column: " + column);
                        jTable1.setColumnSelectionInterval(column + 1, column + 1);
                        jTable1.setRowSelectionInterval(row, row);
            /** This method is called from within the constructor to
             * initialize the form.
             * WARNING: Do NOT modify this code. The content of this method is
             * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents()
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            btnAddItem = new javax.swing.JButton();
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][]
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                new String []
                    "Title 1", "Title 2", "Title 3", "Title 4"
            jScrollPane1.setViewportView(jTable1);
            btnAddItem.setText("Add Item");
            btnAddItem.addActionListener(new java.awt.event.ActionListener()
                public void actionPerformed(java.awt.event.ActionEvent evt)
                    btnAddItemActionPerformed(evt);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
            this.setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(layout.createSequentialGroup()
                            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 589, Short.MAX_VALUE)
                            .addContainerGap())
                        .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                            .add(btnAddItem)
                            .add(264, 264, 264))))
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 163, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(49, 49, 49)
                    .add(btnAddItem)
                    .addContainerGap(54, Short.MAX_VALUE))
        }// </editor-fold>                       
        private void btnAddItemActionPerformed(java.awt.event.ActionEvent evt)                                          
            ViewItems.this.myModel.addRow();
        // Variables declaration - do not modify                    
        private javax.swing.JButton btnAddItem;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration                  
        }Edited by: greenockboy on Oct 15, 2007 8:17 PM

  • 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.

  • Prevent jtable cell edit!!!!

    when i double click any cell in a table it gets editable. but i dont wish to do this. i want all the cells in the table non editable. so nobody can change the cell content. anyone tell me how to do this. thank you.

    Then search the forum for code that uses the isCellEditable(...) method to see examples.
    Or you could even read the JTable API of all things. Then follow the link to the Swing tutorial on "How to Use Tables" which also has an example of overriding the isCellEditable(...) method. The code in the tutorial overrides the method of the TableModel. I prefer to override the method in the JTable.

  • How to edit jtable programmatically?

    id like to know how to edit jtable cell programmatically.
    thanks!

    override
    getTableCellEditorComponent in customized
    TableCellEditor.Hi,
    hmm ... if that's that, what he want to know? - I guess, he wants to know how to change values of the JTable by program.
    Every JTable has an underlying TableDataModel that holds the values of the tablecells. You can retrieve this model by the getModel()-method of the JTable.
    To get a value from the model use method getValueAt(row,column) of the model.
    To set a value in the model use method setValueAt(object,row,column) of the model.
    See the TableModel-interface-Documentation for other methods.
    greetings Marsian

  • Reporting query - Cell editing

    Hi Experts !!
    I need some documents related to embedding multiple queries and formatting a workbook.
    I need more info on cell editing.
    Appreciate your help !!
    Thanks.

    hi yogita,
    Check the below link for checking the cell editing functionality
    [Cell editing|http://sap.seo-gym.com/celleditingBex.pdf]
    Regards
    KP
    have you tried to search in google of SDN before posting?

  • Stopping cell editing in a JTable using a JComboBox editor w/ AutoComplete

    Hi there! Me again with more questions!
    I'm trying to figure out the finer parts of JTable navigation and editing controls. It's getting a bit confusing. The main problem I'm trying to solve is how to make a JTable using a combo box editor stop editing by hitting the 'enter' key in the same fashion as a JTextField editor. This is no regular DefaultCellEditor though -- it's one that uses the SwingX AutoCompleteDecorator. I have an SSCCE that demonstrates the issue:
    import java.awt.Component;
    import java.awt.EventQueue;
    import javax.swing.AbstractCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JTable;
    import javax.swing.WindowConstants;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellEditor;
    import javax.swing.table.TableModel;
    import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
    public class AutoCompleteCellEditorTest extends JFrame {
      public AutoCompleteCellEditorTest() {
        JTable table = new JTable();
        Object[] items = {"A", "B", "C", "D"};
        TableModel tableModel = new DefaultTableModel(2, 2);
        table.setModel(tableModel);
        table.getColumnModel().getColumn(0).setCellEditor(new ComboCellEditor(items));
        getContentPane().add(table);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        pack();
      private class ComboCellEditor extends AbstractCellEditor implements TableCellEditor {
        private JComboBox comboBox;
        public ComboCellEditor(Object[] items) {
          this.comboBox = new JComboBox(items);
          AutoCompleteDecorator.decorate(this.comboBox);
        public Object getCellEditorValue() {
          return this.comboBox.getSelectedItem();
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
          comboBox.setSelectedItem(value);
          return comboBox;
      public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
          public void run() {
            new AutoCompleteCellEditorTest().setVisible(true);
    }Problem 1: Starting to 'type' into the AutoCompleteDecorate combo box doesn't cause it to start editing. You have to hit F2, it would appear. I've also noticed this behaviour with other JComboBox editors. Ideally that would be fixed too. Not sure how to do this one.
    Problem 2: After editing has started (say, with the F2 key), you may start typing. If you type one of A, B, C, or D, the item appears. That's all good. Then you try to 'complete' the edit by hitting the 'enter' key... and nothing happens. The 'tab' key works, but it puts you to the next cell. I would like to make the 'enter' key stop editing, and stay in the current cell.
    I found some stuff online suggesting you take the input map of the table and set the Enter key so that it does the same thing as tab. Even though that's not exactly what I desired (I wanted the same cell to be active), it didn't work anyway.
    I also tried setting a property on the JComboBox that says that it's a table cell editor combo box (just like the DefaultCellEditor), but that didn't work either. I think the reason that fails is because the AutoCompleteDecorator sets isEditable to true, and that seems to stop the enter key from doing anything.
    After tracing endless paths through processKeyBindings calls, I'm not sure I'm any closer to a solution. I feel like this should be a fairly straightforward thing but I'm having a fair amount of difficulty with it.
    Thanks for any direction you can provide!

    Hi Jeanette,
    Thanks for your advice. I looked again at the DefaultCellEditor. You are correct that I am not firing messages for fireEditingStopped() and fireEditingCancelled(). Initially I had copied the behaviour from DefaultCellEditor but had trimmed it out. I assumed that since I was extending AbstractCellEditor and it has them implemented correctly that I was OK. But I guess that's not the case! The problem I'm having with implementing the Enter key stopping the editing is that:
    1) The DefaultCellEditor stops cell editing on any actionPerformed. Based on my tests, actionPerformed gets called whenever a single key gets pressed. I don't want to end the editing on the AutoCompleteDecorated box immediately -- I'd like to wait until the user is happy with his or her selection and has hit 'Enter' before ending cell editing. Thus, ending cell editing within the actionPerformed listener on the JComboBox (or JXComboBox, as I've made it now) will not work. As soon as you type a single key, if it is valid, the editing ends immediately.
    2) I tried to add a key listener to the combo box to pick up on the 'Enter' key and end the editing there. However, it appears that the combo box does not receive the key strokes. I guess they're going to the AutoCompleteDecorator and being consumed there so the combo box does not receive them. If I could pick up on the 'Enter' key there, then that would work too.
    I did more reading about input maps and action maps last night. Although informative, I'm not sure how far it got me with this problem because if the text field in the AutoCompleteDecorator takes the keystroke, I'm not sure how I'm going to find out about it in the combo box.
    By the way, when you said 'They are fixed... in a recent version of SwingX', does that mean 1.6.2? That's what I'm using.
    Thanks!
    P.S. - Maybe I should create a new question for this? I wanted to mark your answer as helpful but I already closed the thread by marking the answer to the first part as correct. Sorry!
    Edited by: aardvarkk on Jan 27, 2011 7:41 AM - Added SwingX versioning question.

  • Returning index of selected comp... jComboBox that is editing a jTable cell

    so, i'm using an array to populate the choices of a combobox
        public String[] progCodes = new String[]{"Standard","Restricted","Combined","Special"};which i'm using to edit a cell in a jtable
    baseCatTable.getColumnModel().getColumn(4).setCellEditor(new DefaultCellEditor(new JComboBox(progCodes)));and when i get the value
    System.out.println(baseCatTable.getValueAt(0, 4))i'd like to return the index of the selected item in the combo box instead of the text:
    Standard
    any suggestions?
    Edited by: hansbig on Jan 24, 2008 5:04 PM

    sorry, but i'm using an IDE and it generates a lot of fluffy code.
    * ProblemView.java
    package problem;
    import org.jdesktop.application.Action;
    import org.jdesktop.application.ResourceMap;
    import org.jdesktop.application.SingleFrameApplication;
    import org.jdesktop.application.FrameView;
    import org.jdesktop.application.TaskMonitor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultCellEditor;
    import javax.swing.Timer;
    import javax.swing.Icon;
    import javax.swing.JComboBox;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    * The application's main frame.
    public class ProblemView extends FrameView {
        public ProblemView(SingleFrameApplication app) {
            super(app);
            initComponents();
            edit = new JComboBox(words);
            // status bar initialization - message timeout, idle icon and busy animation, etc
            ResourceMap resourceMap = getResourceMap();
            int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
            messageTimer = new Timer(messageTimeout, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    statusMessageLabel.setText("");
            messageTimer.setRepeats(false);
            int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
            for (int i = 0; i < busyIcons.length; i++) {
                busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
            busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                    statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
            statusAnimationLabel.setIcon(idleIcon);
            progressBar.setVisible(false);
            // connecting action tasks to status bar via TaskMonitor
            TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
            taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
                public void propertyChange(java.beans.PropertyChangeEvent evt) {
                    String propertyName = evt.getPropertyName();
                    if ("started".equals(propertyName)) {
                        if (!busyIconTimer.isRunning()) {
                            statusAnimationLabel.setIcon(busyIcons[0]);
                            busyIconIndex = 0;
                            busyIconTimer.start();
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(true);
                    } else if ("done".equals(propertyName)) {
                        busyIconTimer.stop();
                        statusAnimationLabel.setIcon(idleIcon);
                        progressBar.setVisible(false);
                        progressBar.setValue(0);
                    } else if ("message".equals(propertyName)) {
                        String text = (String)(evt.getNewValue());
                        statusMessageLabel.setText((text == null) ? "" : text);
                        messageTimer.restart();
                    } else if ("progress".equals(propertyName)) {
                        int value = (Integer)(evt.getNewValue());
                        progressBar.setVisible(true);
                        progressBar.setIndeterminate(false);
                        progressBar.setValue(value);
        @Action
        public void showAboutBox() {
            if (aboutBox == null) {
                JFrame mainFrame = ProblemApp.getApplication().getMainFrame();
                aboutBox = new ProblemAboutBox(mainFrame);
                aboutBox.setLocationRelativeTo(mainFrame);
            ProblemApp.getApplication().show(aboutBox);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            mainPanel = new javax.swing.JPanel();
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            jButton1 = new javax.swing.JButton();
            menuBar = new javax.swing.JMenuBar();
            javax.swing.JMenu fileMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
            javax.swing.JMenu helpMenu = new javax.swing.JMenu();
            javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
            statusPanel = new javax.swing.JPanel();
            javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
            statusMessageLabel = new javax.swing.JLabel();
            statusAnimationLabel = new javax.swing.JLabel();
            progressBar = new javax.swing.JProgressBar();
            mainPanel.setName("mainPanel"); // NOI18N
            jScrollPane1.setName("jScrollPane1"); // NOI18N
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null}
                new String [] {
                    "Title 1"
            jTable1.setColumnSelectionAllowed(true);
            jTable1.setName("jTable1"); // NOI18N
            jScrollPane1.setViewportView(jTable1);
            jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
            jTable1.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(edit));
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(problem.ProblemApp.class).getContext().getResourceMap(ProblemView.class);
            jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
            jButton1.setName("jButton1"); // NOI18N
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
            javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
            mainPanel.setLayout(mainPanelLayout);
            mainPanelLayout.setHorizontalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(mainPanelLayout.createSequentialGroup()
                            .addGap(46, 46, 46)
                            .addComponent(jButton1)))
                    .addContainerGap(12, Short.MAX_VALUE))
            mainPanelLayout.setVerticalGroup(
                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(mainPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(jButton1)
                    .addContainerGap(18, Short.MAX_VALUE))
            menuBar.setName("menuBar"); // NOI18N
            fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
            fileMenu.setName("fileMenu"); // NOI18N
            javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(problem.ProblemApp.class).getContext().getActionMap(ProblemView.class, this);
            exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
            exitMenuItem.setName("exitMenuItem"); // NOI18N
            fileMenu.add(exitMenuItem);
            menuBar.add(fileMenu);
            helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
            helpMenu.setName("helpMenu"); // NOI18N
            aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
            aboutMenuItem.setName("aboutMenuItem"); // NOI18N
            helpMenu.add(aboutMenuItem);
            menuBar.add(helpMenu);
            statusPanel.setName("statusPanel"); // NOI18N
            statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
            statusMessageLabel.setName("statusMessageLabel"); // NOI18N
            statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
            progressBar.setName("progressBar"); // NOI18N
            javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
            statusPanel.setLayout(statusPanelLayout);
            statusPanelLayout.setHorizontalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(statusMessageLabel)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(statusAnimationLabel)
                    .addContainerGap())
            statusPanelLayout.setVerticalGroup(
                statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(statusPanelLayout.createSequentialGroup()
                    .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(statusMessageLabel)
                        .addComponent(statusAnimationLabel)
                        .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(3, 3, 3))
            setComponent(mainPanel);
            setMenuBar(menuBar);
            setStatusBar(statusPanel);
        }// </editor-fold>
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
            System.out.println(jTable1.getValueAt(0, 0));
            System.out.println(edit.getSelectedIndex());
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        private javax.swing.JPanel mainPanel;
        private javax.swing.JMenuBar menuBar;
        private javax.swing.JProgressBar progressBar;
        private javax.swing.JLabel statusAnimationLabel;
        private javax.swing.JLabel statusMessageLabel;
        private javax.swing.JPanel statusPanel;
        // End of variables declaration
        public String[] words = new String[]{"one","two"};
        public JComboBox edit;
        private final Timer messageTimer;
        private final Timer busyIconTimer;
        private final Icon idleIcon;
        private final Icon[] busyIcons = new Icon[15];
        private int busyIconIndex = 0;
        private JDialog aboutBox;
    * ProblemApp.java
    package problem;
    import org.jdesktop.application.Application;
    import org.jdesktop.application.SingleFrameApplication;
    * The main class of the application.
    public class ProblemApp extends SingleFrameApplication {
         * At startup create and show the main frame of the application.
        @Override protected void startup() {
            show(new ProblemView(this));
         * This method is to initialize the specified window by injecting resources.
         * Windows shown in our application come fully initialized from the GUI
         * builder, so this additional configuration is not needed.
        @Override protected void configureWindow(java.awt.Window root) {
         * A convenient static getter for the application instance.
         * @return the instance of ProblemApp
        public static ProblemApp getApplication() {
            return Application.getInstance(ProblemApp.class);
         * Main method launching the application.
        public static void main(String[] args) {
            launch(ProblemApp.class, args);
    }i'm getting:
    init:
    deps-jar:
    Compiling 1 source file to C:\Documents and Settings\1\My Documents\NetBeansProjects\problem\build\classes
    compile:
    run:
    Jan 24, 2008 7:58:36 PM org.jdesktop.application.Application$1 run
    SEVERE: Application class problem.ProblemApp failed to launch
    java.lang.NullPointerException
    at javax.swing.DefaultCellEditor.<init>(DefaultCellEditor.java:117)
    at problem.ProblemView.initComponents(ProblemView.java:136)
    at problem.ProblemView.<init>(ProblemView.java:29)
    at problem.ProblemApp.startup(ProblemApp.java:19)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Application class problem.ProblemApp failed to launch
    at org.jdesktop.application.Application$1.run(Application.java:177)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    Caused by: java.lang.NullPointerException
    at javax.swing.DefaultCellEditor.<init>(DefaultCellEditor.java:117)
    at problem.ProblemView.initComponents(ProblemView.java:136)
    at problem.ProblemView.<init>(ProblemView.java:29)
    at problem.ProblemApp.startup(ProblemApp.java:19)
    at org.jdesktop.application.Application$1.run(Application.java:171)
    ... 8 more
    BUILD SUCCESSFUL (total time: 2 seconds)
    also, I made a zip file of the project and put it up here:
    http://www.geocities.com/hansbigtree/problem.zip
    thanks.

  • Default behaviour of the Escape key while editing a cell in JTable??

    Hi all,
    i have a Jtable which get its data from an own model object which extends DefaultTableModel.
    If i overwrite the isCellEditable(row, col) method within the tablemodel object and set a specific column to editable, then i notice while editing a cell in that column that the default behaviour of the Escape key is that independet from what you have entered before in to the cell the editing stops and the cell gets the value it had before editing.
    This is the case for me even if i apply a custom editor to a column (one that extends DefaultCellEditor). It is just a JTextField that limits the number of digits a user can enter. Everything works fine. If the user edits the cell and presses ENTER or the "down arrow key" i can check what he has entered with the help of the getCellEditorValue() method. But if the user hits the ESC key after editing a cell this method is not invoked!!!
    My question is :
    is there any way to detect that the user cancels editing with the ESC-key.
    this is very important for me because if the user goes editing the cell i lock the related record in the database, if i cannot detect this it is locked till the application terminates.
    Thanks for any help in advance

    I try override the JTable editingCanceled() ==> does not work.
    I try the addCellEditorListener( CellEditorListener l ) ==> does not work.
    Finally, I try the addKeyListener ==> it works.
    Here is a quick demo. program:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class Test {
    public static void main(String[] args){
    JFrame f = new JFrame();
    String[] colName = {"a", "b"};
    String[][] rowData = {{"1", "2"}, {"3", "4"}};
    JTable table = new JTable(rowData, colName);
    JTextField t = new JTextField(10);
    t.setBackground(Color.red);
    t.addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
    // do what ever you want ex. un-lock table
    System.out.println("ESCAPE");
    DefaultCellEditor editor = new DefaultCellEditor(t);
    TableColumnModel colModel = table.getColumnModel();
    for (int i = colModel.getColumnCount()-1; i >= 0; i--) {
    colModel.getColumn(i).setCellEditor(editor);
    f.setContentPane(new JScrollPane(table));
    f.pack();
    f.setVisible(true);

Maybe you are looking for

  • Can I trust iTunes in the Cloud to retain past purchases?

    I've been using iTunes for several years now to download and watch television episodes, since long before the advent of iTunes in the Cloud, with its ability to re-download previously purchased music, television, and (most recently) movies. Prior to

  • How to get rid of the reference lines on the front panel

    I forgot how I created a couple of horizontal and vertical reference lines on the front panel. It looks like the origin lines on the front panel. When I move my program to another monitor with different resolution, all the layout is messed up because

  • Hard Drive Reads in Disk Utility but not in Finder

    I have a Seagate FreeAgent hard drive that is configured to NTFS. I use software to read and write to this on my macbook pro. I have plugged my hard drive into my macbook this morning and it will only read in Disk Utility, and not show up at all in F

  • Fill all required fields SAPMF02K 0111 SZA1_D0100-TITLE_MEDI

    Hi all Scenario MDM - Xi - R3 We're sending the idoc from mdm to xi, but we get an error in the R3 side about: Fill all required fields SAPMF02K 0111 SZA1_D0100-TITLE_MEDI. I read some notes and i have tried to change some things about MSGFN value 00

  • Backing up your important files

    Found this article on mac help and performed as instructed (items 1 ~ 3) for the document folder as well as preferences. Seemed to work, however, when I dragged the itunes icon on the far left to the burn folder on the desktop it deleted the itunes i