<tfoot id='mPBcG'></tfoot>
  • <i id='mPBcG'><tr id='mPBcG'><dt id='mPBcG'><q id='mPBcG'><span id='mPBcG'><b id='mPBcG'><form id='mPBcG'><ins id='mPBcG'></ins><ul id='mPBcG'></ul><sub id='mPBcG'></sub></form><legend id='mPBcG'></legend><bdo id='mPBcG'><pre id='mPBcG'><center id='mPBcG'></center></pre></bdo></b><th id='mPBcG'></th></span></q></dt></tr></i><div id='mPBcG'><tfoot id='mPBcG'></tfoot><dl id='mPBcG'><fieldset id='mPBcG'></fieldset></dl></div>

        <legend id='mPBcG'><style id='mPBcG'><dir id='mPBcG'><q id='mPBcG'></q></dir></style></legend>

      1. <small id='mPBcG'></small><noframes id='mPBcG'>

          <bdo id='mPBcG'></bdo><ul id='mPBcG'></ul>
      2. JTable:检测单元格数据变化

        时间:2023-09-29
        <i id='JNKaa'><tr id='JNKaa'><dt id='JNKaa'><q id='JNKaa'><span id='JNKaa'><b id='JNKaa'><form id='JNKaa'><ins id='JNKaa'></ins><ul id='JNKaa'></ul><sub id='JNKaa'></sub></form><legend id='JNKaa'></legend><bdo id='JNKaa'><pre id='JNKaa'><center id='JNKaa'></center></pre></bdo></b><th id='JNKaa'></th></span></q></dt></tr></i><div id='JNKaa'><tfoot id='JNKaa'></tfoot><dl id='JNKaa'><fieldset id='JNKaa'></fieldset></dl></div>

        <legend id='JNKaa'><style id='JNKaa'><dir id='JNKaa'><q id='JNKaa'></q></dir></style></legend>

                <tfoot id='JNKaa'></tfoot>
                  <bdo id='JNKaa'></bdo><ul id='JNKaa'></ul>
                • <small id='JNKaa'></small><noframes id='JNKaa'>

                    <tbody id='JNKaa'></tbody>
                  本文介绍了JTable:检测单元格数据变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 Netbeans 中,我使用 GUI Builder 将 JTable 插入到我的应用程序中.

                  到目前为止,我只有一个类 (CustomerDB):

                  I have just one class (CustomerDB) so far which is:

                  package CustomerDB;
                  
                  import [...];
                  
                  public class CustomerDB extends javax.swing.JFrame {
                  
                      CellEditorListener ChangeNotification = new CellEditorListener() {
                          public void editingCanceled(ChangeEvent e) {
                              System.out.println("The user canceled editing.");
                          }
                  
                          public void editingStopped(ChangeEvent e) {
                              System.out.println("The user stopped editing successfully.");
                          }
                      };
                  
                      public CustomerDB() {
                          customerTable = new javax.swing.JTable();
                          customerTable.setModel(new javax.swing.table.DefaultTableModel(
                              new Object [][] {
                                  {null, null, null, null},
                                  {null, null, null, null},
                                  {null, null, null, null},
                                  {null, null, null, null},
                                  {null, null, null, null},
                                  {null, null, null, null},
                                  {null, null, null, null},
                                  {null, null, null, null},
                                  {null, null, null, null},
                                  {null, null, null, null}
                              },
                              new String [] {
                                  "ID", "Name", "Address", "Phone"
                              }
                          ) {
                              Class[] types = new Class [] {
                                  java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
                              };
                  
                              public Class getColumnClass(int columnIndex) {
                                  return types [columnIndex];
                              }
                          });
                          customerTable.getDefaultEditor(String.class).addCellEditorListener(ChangeNotification);
                      } 
                  
                      public static void main(String args[]) {
                          java.awt.EventQueue.invokeLater(new Runnable() {
                              public void run() {
                                  new CustomerDB().setVisible(true);
                              }
                          });
                      }
                  
                      // Variables declaration - do not modify
                      [...]
                      private javax.swing.JTable customerTable;
                      [...]
                      // End of variables declaration
                  
                  }
                  

                  每当用户更改表格中的数据时,我都想获取该单元格的旧值(可选)和新值.

                  为了获取这些数据,我尝试实现一个事件监听器:

                  In order to get this data, I tried to implement an event listener:

                      CellEditorListener ChangeNotification = new CellEditorListener() {
                          public void editingCanceled(ChangeEvent e) {
                              System.out.println("The user canceled editing.");
                          }
                  
                          public void editingStopped(ChangeEvent e) {
                              System.out.println("The user stopped editing successfully.");
                          }
                      };
                  

                  然后我将这个 CellEditorListener 分配给表格(它的单元格编辑器):

                      customerTable.getDefaultEditor(String.class).addCellEditorListener(ChangeNotification);
                  

                  到目前为止有效.但它还不能让我检测到这个单元格的旧值和新值.我还需要做什么?

                  非常感谢您!

                  推荐答案

                  但它还不能让我检测到这个单元格的旧值和新值.我还需要做什么?

                  But it doesn't yet enable me to detect the old and the new value of this cell. What else do I have to do?

                  使用 TableModelListener 来监听变化更容易,但它仍然存在无法访问旧值的问题.

                  It is easier to use a TableModelListener to listen for changes but it still has the problem of not being able to access the old value.

                  查看表格单元侦听器,了解可让您访问的解决方案旧值"和新值".

                  Check out the Table Cell Listener for a solution that gives you access to the "old value" as well as the "new value".

                  这篇关于JTable:检测单元格数据变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:JSpinner 值变化事件 下一篇:如何设置 Java 默认按钮以对 ENTER 键 _released_ 做出

                  相关文章

                  最新文章

                    <small id='JZRcW'></small><noframes id='JZRcW'>

                  1. <i id='JZRcW'><tr id='JZRcW'><dt id='JZRcW'><q id='JZRcW'><span id='JZRcW'><b id='JZRcW'><form id='JZRcW'><ins id='JZRcW'></ins><ul id='JZRcW'></ul><sub id='JZRcW'></sub></form><legend id='JZRcW'></legend><bdo id='JZRcW'><pre id='JZRcW'><center id='JZRcW'></center></pre></bdo></b><th id='JZRcW'></th></span></q></dt></tr></i><div id='JZRcW'><tfoot id='JZRcW'></tfoot><dl id='JZRcW'><fieldset id='JZRcW'></fieldset></dl></div>
                    <legend id='JZRcW'><style id='JZRcW'><dir id='JZRcW'><q id='JZRcW'></q></dir></style></legend>
                    <tfoot id='JZRcW'></tfoot>
                        <bdo id='JZRcW'></bdo><ul id='JZRcW'></ul>