?? jtable.java
字號:
// TODO Auto-generated method stub } public Accessible getAccessibleColumnDescription(int c) { // TODO Auto-generated method stub return null; } public void setAccessibleColumnDescription(int c, Accessible description) { // TODO Auto-generated method stub } public boolean isAccessibleSelected(int r, int c) { // TODO Auto-generated method stub return false; } public boolean isAccessibleRowSelected(int r) { // TODO Auto-generated method stub return false; } public boolean isAccessibleColumnSelected(int c) { // TODO Auto-generated method stub return false; } public int[] getSelectedAccessibleRows() { // TODO Auto-generated method stub return null; } public int[] getSelectedAccessibleColumns() { // TODO Auto-generated method stub return null; } /** * Returns the accessible row at the specified index. * * @param index the index for which to query the row * * @return the row number at the specified table index */ public int getAccessibleRowAtIndex(int index) { // TODO: Back this up by a Mauve test and update API docs accordingly. return index / getColumnCount(); } /** * Returns the accessible column at the specified index. * * @param index the index for which to query the column * * @return the column number at the specified table index */ public int getAccessibleColumnAtIndex(int index) { // TODO: Back this up by a Mauve test and update API docs accordingly. return index % getColumnCount(); } /** * Returns the accessible child index at the specified column and row. * * @param row the row * @param column the column * * @return the index of the accessible child at the specified row and * column */ public int getAccessibleIndexAt(int row, int column) { // TODO: Back this up by a Mauve test and update API docs accordingly. return row * getColumnCount() + column; } } /** * Handles property changes from the <code>TableColumn</code>s of this * <code>JTable</code>. * * More specifically, this triggers a {@link #revalidate()} call if the * preferredWidth of one of the observed columns changes. */ class TableColumnPropertyChangeHandler implements PropertyChangeListener { /** * Receives notification that a property of the observed TableColumns has * changed. * * @param ev the property change event */ public void propertyChange(PropertyChangeEvent ev) { if (ev.getPropertyName().equals("preferredWidth")) { JTableHeader header = getTableHeader(); if (header != null) // Do nothing if the table is in the resizing mode. if (header.getResizingColumn() == null) { TableColumn col = (TableColumn) ev.getSource(); header.setResizingColumn(col); doLayout(); header.setResizingColumn(null); } } } } /** * A cell renderer for boolean values. */ private class BooleanCellRenderer extends DefaultTableCellRenderer { /** * The CheckBox that is used for rendering. */ private final JCheckBox checkBox = new JCheckBox(); /** * Get the check box. */ JCheckBox getCheckBox() { return checkBox; } /** * Returns the component that is used for rendering the value. * * @param table the JTable * @param value the value of the object * @param isSelected is the cell selected? * @param hasFocus has the cell the focus? * @param row the row to render * @param column the cell to render * @return this component (the default table cell renderer) */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (isSelected) { checkBox.setBackground(table.getSelectionBackground()); checkBox.setForeground(table.getSelectionForeground()); } else { checkBox.setBackground(table.getBackground()); checkBox.setForeground(table.getForeground()); } if (hasFocus) { checkBox.setBorder( UIManager.getBorder("Table.focusCellHighlightBorder")); if (table.isCellEditable(row, column)) { checkBox.setBackground( UIManager.getColor("Table.focusCellBackground")); checkBox.setForeground( UIManager.getColor("Table.focusCellForeground")); } } else checkBox.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); // Null is rendered as false. if (value == null) checkBox.setSelected(false); else { Boolean boolValue = (Boolean) value; checkBox.setSelected(boolValue.booleanValue()); } return checkBox; } } /** * A cell renderer for Date values. */ private class DateCellRenderer extends DefaultTableCellRenderer { /** * Returns the component that is used for rendering the value. * * @param table the JTable * @param value the value of the object * @param isSelected is the cell selected? * @param hasFocus has the cell the focus? * @param row the row to render * @param column the cell to render * * @return this component (the default table cell renderer) */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof Date) { Date dateValue = (Date) value; DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); setText(df.format(dateValue)); } return this; } } /** * A cell renderer for Double values. */ private class DoubleCellRenderer extends DefaultTableCellRenderer { /** * Creates a new instance of NumberCellRenderer. */ public DoubleCellRenderer() { setHorizontalAlignment(JLabel.RIGHT); } /** * Returns the component that is used for rendering the value. * * @param table the JTable * @param value the value of the object * @param isSelected is the cell selected? * @param hasFocus has the cell the focus? * @param row the row to render * @param column the cell to render * * @return this component (the default table cell renderer) */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof Double) { Double doubleValue = (Double) value; NumberFormat nf = NumberFormat.getInstance(); setText(nf.format(doubleValue.doubleValue())); } return this; } } /** * A cell renderer for Float values. */ private class FloatCellRenderer extends DefaultTableCellRenderer { /** * Creates a new instance of NumberCellRenderer. */ public FloatCellRenderer() { setHorizontalAlignment(JLabel.RIGHT); } /** * Returns the component that is used for rendering the value. * * @param table the JTable * @param value the value of the object * @param isSelected is the cell selected? * @param hasFocus has the cell the focus? * @param row the row to render * @param column the cell to render * * @return this component (the default table cell renderer) */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof Float) { Float floatValue = (Float) value; NumberFormat nf = NumberFormat.getInstance(); setText(nf.format(floatValue.floatValue())); } return this; } } /** * A cell renderer for Number values. */ private class NumberCellRenderer extends DefaultTableCellRenderer { /** * Creates a new instance of NumberCellRenderer. */ public NumberCellRenderer() { setHorizontalAlignment(JLabel.RIGHT); } } /** * A cell renderer for Icon values. */ private class IconCellRenderer extends DefaultTableCellRenderer { /** * Returns the component that is used for rendering the value. * * @param table the JTable * @param value the value of the object * @param isSelected is the cell selected? * @param hasFocus has the cell the focus? * @param row the row to render * @param column the cell to render * * @return this component (the default table cell renderer) */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof Icon) { Icon iconValue = (Icon) value; setIcon(iconValue); setText(""); } return this; } } /** * The JTable text component (used in editing) always has the table * as its parent. The scrollRectToVisible must be adjusted taking the * relative component position. * * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) */ private class TableTextField extends JTextField { /** * Create the text field without the border. */ TableTextField() { setBorder(BorderFactory.createLineBorder(getGridColor(), 2)); } /** * With not this method overridden, the scroll pane scrolls to the * top left cornec (untranslated position of the caret) after the first * keystroke. */ public void scrollRectToVisible(Rectangle r) { // Do nothing here. If the editing session starts outside the visible // bounds, the editCellAt will scroll. } } private static final long serialVersionUID = 3876025080382781659L; /** * This table, for referring identically name methods from inner classes. */ final JTable this_table = this; /** * When resizing columns, do not automatically change any columns. In this * case the table should be enclosed in a {@link JScrollPane} in order to * accomodate cases in which the table size exceeds its visible area. */ public static final int AUTO_RESIZE_OFF = 0; /** * When resizing column <code>i</code>, automatically change only the * single column <code>i+1</code> to provide or absorb excess space * requirements. */ public static final int AUTO_RESIZE_NEXT_COLUMN = 1; /** * When resizing column <code>i</code> in a table of <code>n</code> * columns, automatically change all columns in the range <code>[i+1, * n)</code>, uniformly, to provide or absorb excess space requirements. */ public static final int AUTO_RESIZE_SUBSEQUENT_COLUMNS = 2; /** * When resizing column <code>i</code> in a table of <code>n</code> * columns, automatically change all columns in the range <code>[0, * n)</code> (with the exception of column i) uniformly, to provide or * absorb excess space requirements. */ public static final int AUTO_RESIZE_ALL_COLUMNS = 4; /** * When resizing column <code>i</code> in a table of <code>n</code> * columns, automatically change column <code>n-1</code> (the last column * in the table) to provide or absorb excess space requirements. */ public static final int AUTO_RESIZE_LAST_COLUMN = 3; /** * A table mapping {@link java.lang.Class} objects to * {@link TableCellEditor} objects. This table is consulted by the * FIXME */ protected Hashtable defaultEditorsByColumnClass;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -