⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jtable.java

📁 Mac OS X 10.4.9 for x86 Source Code gcc 实现源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
  /**   * Get the value of the {@link #columnModel} property.   *   * @return The current value of the property   */  public TableColumnModel getColumnModel()  {    return columnModel;  }  /**   * Get the value of the {@link #selectedColumn} property by   * delegation to the @{link #columnModel} field.   *   * @return The current value of the selectedColumn property   */  public int getSelectedColumn()  {    return columnModel.getSelectionModel().getMinSelectionIndex();  }  private static int countSelections(ListSelectionModel lsm)  {    int lo = lsm.getMinSelectionIndex();    int hi = lsm.getMaxSelectionIndex();    int sum = 0;    if (lo != -1 && hi != -1)      {        switch (lsm.getSelectionMode())          {          case ListSelectionModel.SINGLE_SELECTION:            sum = 1;            break;                      case ListSelectionModel.SINGLE_INTERVAL_SELECTION:            sum = hi - lo + 1;            break;                      case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:                    for (int i = lo; i <= hi; ++i)              if (lsm.isSelectedIndex(i))                        ++sum;            break;          }      }    return sum;  }  private static int[] getSelections(ListSelectionModel lsm)  {    int sz = countSelections(lsm);    int [] ret = new int[sz];    int lo = lsm.getMinSelectionIndex();    int hi = lsm.getMaxSelectionIndex();    int j = 0;    java.util.ArrayList ls = new java.util.ArrayList();    if (lo != -1 && hi != -1)      {        switch (lsm.getSelectionMode())          {          case ListSelectionModel.SINGLE_SELECTION:            ret[0] = lo;            break;                      case ListSelectionModel.SINGLE_INTERVAL_SELECTION:                        for (int i = lo; i <= hi; ++i)              ret[j++] = i;            break;                      case ListSelectionModel.MULTIPLE_INTERVAL_SELECTION:                    for (int i = lo; i <= hi; ++i)              if (lsm.isSelectedIndex(i))                        ret[j++] = i;            break;          }      }    return ret;  }  /**   * Get the value of the {@link #selectedColumnCount} property by   * delegation to the @{link #columnModel} field.   *   * @return The current value of the selectedColumnCount property   */    public int getSelectedColumnCount()  {    return countSelections(columnModel.getSelectionModel());  }  /**   * Get the value of the {@link #selectedColumns} property by   * delegation to the @{link #columnModel} field.   *   * @return The current value of the selectedColumns property   */  public int[] getSelectedColumns()  {    return getSelections(columnModel.getSelectionModel());  }  /**   * Get the value of the {@link #columnSelectionAllowed} property.   *   * @return The current value of the columnSelectionAllowed property   */  public boolean getColumnSelectionAllowed()  {    return getColumnModel().getColumnSelectionAllowed();  }  /**   * Get the value of the {@link #selectedRowCount} property by   * delegation to the @{link #selectionModel} field.   *   * @return The current value of the selectedRowCount property   */  public int getSelectedRowCount()  {    return countSelections(selectionModel);  }  /**   * Get the value of the {@link #selectedRows} property by   * delegation to the @{link #selectionModel} field.   *   * @return The current value of the selectedRows property   */  public int[] getSelectedRows()  {    return getSelections(selectionModel);  }  /**   * Get the value of the {@link #accessibleContext} property.   *   * @return The current value of the property   */  public AccessibleContext getAccessibleContext()  {    return accessibleContext;  }  /**   * Get the value of the {@link #cellEditor} property.   *   * @return The current value of the property   */  public TableCellEditor getCellEditor()  {    return cellEditor;  }  /**   * Get the value of the {@link #dragEnabled} property.   *   * @return The current value of the property   */  public boolean getDragEnabled()  {    return dragEnabled;  }  /**   * Get the value of the {@link #gridColor} property.   *   * @return The current value of the property   */  public Color getGridColor()  {    return gridColor;  }  /**   * Get the value of the {@link #intercellSpacing} property.   *   * @return The current value of the property   */  public Dimension getIntercellSpacing()  {    return new Dimension(columnModel.getColumnMargin(), rowMargin);  }  /**   * Get the value of the {@link #preferredViewportSize} property.   *   * @return The current value of the property   */  public Dimension getPreferredScrollableViewportSize()  {    return preferredViewportSize;  }  /**   * Get the value of the {@link #selectionBackground} property.   *   * @return The current value of the property   */  public Color getSelectionBackground()  {    return selectionBackground;  }  /**   * Get the value of the {@link #selectionForeground} property.   *   * @return The current value of the property   */  public Color getSelectionForeground()  {    return selectionForeground;  }  /**   * Get the value of the {@link #showHorizontalLines} property.   *   * @return The current value of the property   */  public boolean getShowHorizontalLines()  {    return showHorizontalLines;  }  /**   * Get the value of the {@link #showVerticalLines} property.   *   * @return The current value of the property   */  public boolean getShowVerticalLines()  {    return showVerticalLines;  }  /**   * Get the value of the {@link #tableHeader} property.   *   * @return The current value of the property   */  public JTableHeader getTableHeader()  {    return tableHeader;  }  /**   * Removes specified column from displayable columns of this table.   *   * @param column column to removed   */  public void removeColumn(TableColumn column)  {        columnModel.removeColumn(column);  }  /**   * Moves column at the specified index to new given location.   *   * @param column index of the column to move   * @param targetColumn index specifying new location of the column   */   public void moveColumn(int column,int targetColumn)   {    columnModel.moveColumn(column, targetColumn);  }  /**   * Set the value of the {@link #autoCreateColumnsFromModel} property.   *   * @param a The new value of the autoCreateColumnsFromModel property   */   public void setAutoCreateColumnsFromModel(boolean a)  {    autoCreateColumnsFromModel = a;  }  /**   * Set the value of the {@link #autoResizeMode} property.   *   * @param a The new value of the autoResizeMode property   */   public void setAutoResizeMode(int a)  {    autoResizeMode = a;    revalidate();    repaint();  }  /**   * Set the value of the {@link #rowHeight} property.   *   * @param r The new value of the rowHeight property   */   public void setRowHeight(int r)  {    if (rowHeight < 1)      throw new IllegalArgumentException();        rowHeight = r;    revalidate();    repaint();  }  /**   * Set the value of the {@link #rowMargin} property.   *   * @param r The new value of the rowMargin property   */   public void setRowMargin(int r)  {    rowMargin = r;    revalidate();    repaint();  }  /**   * Set the value of the {@link #rowSelectionAllowed} property.   *   * @param r The new value of the rowSelectionAllowed property   */   public void setRowSelectionAllowed(boolean r)  {    rowSelectionAllowed = r;    repaint();  }  /**   * Set the value of the {@link #cellSelectionEnabled} property.   *   * @param c The new value of the cellSelectionEnabled property   */   public void setCellSelectionEnabled(boolean c)  {    setColumnSelectionAllowed(c);    setRowSelectionAllowed(c);    // for backward-compatibility sake:    cellSelectionEnabled = true;  }  /**   * <p>Set the value of the {@link #dataModel} property.</p>   *   * <p>Unregister <code>this</code> as a {@link TableModelListener} from   * previous {@link #dataModel} and register it with new parameter   * <code>m</code>.</p>   *   * @param m The new value of the model property   */   public void setModel(TableModel m)  {    // Throw exception is m is null.    if (m == null)      throw new IllegalArgumentException();       // Don't do anything if setting the current model again.    if (dataModel == m)      return;        // Remove table as TableModelListener from old model.    if (dataModel != null)      dataModel.removeTableModelListener(this);        if (m != null)      {	// Set property.        dataModel = m;	// Add table as TableModelListener to new model.	dataModel.addTableModelListener(this);	// Automatically create columns.	if (autoCreateColumnsFromModel)	  createColumnsFromModel();      }        // Repaint table.    revalidate();    repaint();  }  /**   * <p>Set the value of the {@link #columnModel} property.</p>   *   * <p>Unregister <code>this</code> as a {@link TableColumnModelListener}   * from previous {@link #columnModel} and register it with new parameter   * <code>c</code>.</p>   *   * @param c The new value of the columnModel property   */   public void setColumnModel(TableColumnModel c)  {    if (c == null)      throw new IllegalArgumentException();    TableColumnModel tmp = columnModel;    if (tmp != null)      tmp.removeColumnModelListener(this);    if (c != null)      c.addColumnModelListener(this);    columnModel = c;    if (dataModel != null && columnModel != null)      {        int ncols = getColumnCount();        for (int i = 0; i < ncols; ++i)          columnModel.getColumn(i).setHeaderValue(dataModel.getColumnName(i));      }    revalidate();    repaint();  }  /**   * Set the value of the {@link #columnSelectionAllowed} property.   *   * @param c The new value of the property   */   public void setColumnSelectionAllowed(boolean c)  {    getColumnModel().setColumnSelectionAllowed(c);    repaint();  }  /**   * <p>Set the value of the {@link #selectionModel} property.</p>   *   * <p>Unregister <code>this</code> as a {@link ListSelectionListener}   * from previous {@link #selectionModel} and register it with new   * parameter <code>s</code>.</p>   *   * @param s The new value of the selectionModel property   */   public void setSelectionModel(ListSelectionModel s)  {    if (s == null)      throw new IllegalArgumentException();    ListSelectionModel tmp = selectionModel;    if (tmp != null)      tmp.removeListSelectionListener(this);    if (s != null)      s.addListSelectionListener(this);    selectionModel = s;  }  /**   * Set the value of the {@link #selectionMode} property by   * delegation to the {@link #selectionModel} field. The same selection   * mode is set for row and column selection models.   *   * @param s The new value of the property   */   public void setSelectionMode(int s)  {     selectionModel.setSelectionMode(s);        columnModel.getSelectionModel().setSelectionMode(s);        repaint();  }  /**   * <p>Set the value of the {@link #cellEditor} property.</p>   *   * <p>Unregister <code>this</code> as a {@link CellEditorListener} from   * previous {@link #cellEditor} and register it with new parameter   * <code>c</code>.</p>   *   * @param c The new value of the cellEditor property   */   public void setCellEditor(TableCellEditor c)  {    TableCellEditor tmp = cellEditor;    if (tmp != null)      tmp.removeCellEditorListener(this);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -