?? jtable.java
字號:
/* JTable.java -- Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package javax.swing;import java.awt.Color;import java.awt.Component;import java.awt.Cursor;import java.awt.Dimension;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.FocusListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.text.DateFormat;import java.text.NumberFormat;import java.util.Date;import java.util.EventObject;import java.util.Hashtable;import java.util.Locale;import java.util.Vector;import javax.accessibility.Accessible;import javax.accessibility.AccessibleComponent;import javax.accessibility.AccessibleContext;import javax.accessibility.AccessibleExtendedTable;import javax.accessibility.AccessibleRole;import javax.accessibility.AccessibleSelection;import javax.accessibility.AccessibleStateSet;import javax.accessibility.AccessibleTable;import javax.accessibility.AccessibleTableModelChange;import javax.swing.event.CellEditorListener;import javax.swing.event.ChangeEvent;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import javax.swing.event.TableColumnModelEvent;import javax.swing.event.TableColumnModelListener;import javax.swing.event.TableModelEvent;import javax.swing.event.TableModelListener;import javax.swing.plaf.TableUI;import javax.swing.table.DefaultTableCellRenderer;import javax.swing.table.DefaultTableColumnModel;import javax.swing.table.DefaultTableModel;import javax.swing.table.JTableHeader;import javax.swing.table.TableCellEditor;import javax.swing.table.TableCellRenderer;import javax.swing.table.TableColumn;import javax.swing.table.TableColumnModel;import javax.swing.table.TableModel;/** * The table component, displaying information, organized in rows and columns. * The table can be placed in the scroll bar and have the optional header * that is always visible. Cell values may be editable after double clicking * on the cell. Cell columns may have various data types, that are * displayed and edited by the different renderers and editors. It is possible * to set different column width. The columns are also resizeable by * dragging the column boundary in the header. */public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, Accessible{ /** * Provides accessibility support for <code>JTable</code>. * * @author Roman Kennke (kennke@aicas.com) */ protected class AccessibleJTable extends AccessibleJComponent implements AccessibleSelection, ListSelectionListener, TableModelListener, TableColumnModelListener, CellEditorListener, PropertyChangeListener, AccessibleExtendedTable { /** * Provides accessibility support for table cells. * * @author Roman Kennke (kennke@aicas.com) */ protected class AccessibleJTableCell extends AccessibleContext implements Accessible, AccessibleComponent { /** * The table of this cell. */ private JTable table; /** * The row index of this cell. */ private int row; /** * The column index of this cell. */ private int column; /** * The index of this cell inside the AccessibleJTable parent. */ private int index; /** * Creates a new <code>AccessibleJTableCell</code>. * * @param t the table * @param r the row * @param c the column * @param i the index of this cell inside the accessible table parent */ public AccessibleJTableCell(JTable t, int r, int c, int i) { table = t; row = r; column = c; index = i; } /** * Returns the accessible row for the table cell. * * @return the accessible row for the table cell */ public AccessibleRole getAccessibleRole() { // TODO: What is the role of the table cell? return AccessibleRole.UNKNOWN; } /** * Returns the accessible state set of this accessible table cell. * * @return the accessible state set of this accessible table cell */ public AccessibleStateSet getAccessibleStateSet() { // TODO: What state shoiuld be returned here? return new AccessibleStateSet(); } /** * Returns the index of this cell in the parent object. * * @return the index of this cell in the parent object */ public int getAccessibleIndexInParent() { return index; } /** * Returns the number of children of this object. Table cells cannot have * children, so we return <code>0</code> here. * * @return <code>0</code> */ public int getAccessibleChildrenCount() { return 0; } /** * Returns the accessible child at index <code>i</code>. Table cells * don't have children, so we return <code>null</code> here. * * @return <code>null</code> */ public Accessible getAccessibleChild(int i) { return null; } /** * Returns the locale setting for this accessible table cell. * * @return the locale setting for this accessible table cell */ public Locale getLocale() { // TODO: For now, we return english here. This must be fixed as soon // as we have a localized Swing. return Locale.ENGLISH; } /** * Returns the accessible context of this table cell. Since accessible * table cells are their own accessible context, we return * <code>this</code>. * * @return the accessible context of this table cell */ public AccessibleContext getAccessibleContext() { return this; } /** * Returns the background color of this cell. * * @return the background color of this cell */ public Color getBackground() { return table.getBackground(); } /** * Sets the background of the cell. Since table cells cannot have * individual background colors, this method does nothing. Set the * background directly on the table instead. * * @param color not used */ public void setBackground(Color color) { // This method does nothing. See API comments. } /** * Returns the foreground color of the table cell. * * @return the foreground color of the table cell */ public Color getForeground() { return table.getForeground(); } /** * Sets the foreground of the cell. Since table cells cannot have * individual foreground colors, this method does nothing. Set the * foreground directly on the table instead. * * @param color not used */ public void setForeground(Color color) { // This method does nothing. See API comments. } /** * Returns the cursor for this table cell. * * @return the cursor for this table cell */ public Cursor getCursor() { return table.getCursor(); } /** * Sets the cursor of the cell. Since table cells cannot have * individual cursors, this method does nothing. Set the * cursor directly on the table instead. * * @param cursor not used */ public void setCursor(Cursor cursor) { // This method does nothing. See API comments. } /** * Returns the font of the table cell. * * @return the font of the table cell */ public Font getFont() { return table.getFont(); } /** * Sets the font of the cell. Since table cells cannot have * individual fonts, this method does nothing. Set the * font directly on the table instead. * * @param font not used */ public void setFont(Font font) { // This method does nothing. See API comments. } /** * Returns the font metrics for a specified font. * * @param font the font for which we return the metrics * * @return the font metrics for a specified font */ public FontMetrics getFontMetrics(Font font) { return table.getFontMetrics(font); } /** * Returns <code>true</code> if this table cell is enabled, * <code>false</code> otherwise. * * @return <code>true</code> if this table cell is enabled, * <code>false</code> otherwise */ public boolean isEnabled() { return table.isEnabled(); } /** * Table cells cannot be disabled or enabled individually, so this method * does nothing. Set the enabled flag on the table itself. * * @param b not used here */ public void setEnabled(boolean b) { // This method does nothing. See API comments. } /** * Returns <code>true</code> if this cell is visible, <code>false</code> * otherwise. * * @return <code>true</code> if this cell is visible, <code>false</code> * otherwise */ public boolean isVisible() { return table.isVisible(); } /** * The visibility cannot be set on individual table cells, so this method * does nothing. Set the visibility on the table itself. * * @param b not used */ public void setVisible(boolean b) { // This method does nothing. See API comments. } /** * Returns <code>true</code> if this table cell is currently showing on * screen. * * @return <code>true</code> if this table cell is currently showing on * screen */ public boolean isShowing() { return table.isShowing(); } /** * Returns <code>true</code> if this table cell contains the location * at <code>point</code>, <code>false</code> otherwise. * <code>point</code> is interpreted as relative to the coordinate system * of the table cell. * * @return <code>true</code> if this table cell contains the location * at <code>point</code>, <code>false</code> otherwise */ public boolean contains(Point point) { Rectangle cellRect = table.getCellRect(row, column, true); cellRect.x = 0; cellRect.y = 0; return cellRect.contains(point); } /** * Returns the screen location of the table cell. * * @return the screen location of the table cell */ public Point getLocationOnScreen() { Point tableLoc = table.getLocationOnScreen(); Rectangle cellRect = table.getCellRect(row, column, true); tableLoc.x += cellRect.x; tableLoc.y += cellRect.y; return tableLoc; } /** * Returns the location of this cell relative to the table's bounds. * * @return the location of this cell relative to the table's bounds */ public Point getLocation() { Rectangle cellRect = table.getCellRect(row, column, true); return new Point(cellRect.x, cellRect.y); } /** * The location of the table cells cannot be manipulated directly, so * this method does nothing. * * @param point not used */ public void setLocation(Point point) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -