📄 tablelayout.java
字号:
/** * Adjusts the width of a single column in this layout. After calling this * method, the caller should request this layout manager to perform the * layout. This can be done with the following code: * * <code> * layout.layoutContainer(container); * container.repaint(); * </code> * * or * * <pre> * window.pack() * </pre> * * If this is not done, the changes in the layout will not be seen until the * container is resized. * * @param i zero-based index of column to set. If this parameter is not * valid, an ArrayOutOfBoundsException will be thrown. * @param size width of the column. This parameter cannot be null. * * @see getColumn */ public void setColumn (int i, double size) { // Make sure size is valid if ((size < 0.0) && (size != FILL) && (size != PREFERRED) && (size != MINIMUM)) { size = 0.0; } // Copy new size columnSpec[i] = size; // Indicate that the cell sizes are not known dirty = true; } /** * Adjusts the height of a single row in this layout. After calling this * method, the caller should request this layout manager to perform the * layout. This can be done with the following code: * * <code> * layout.layoutContainer(container); * container.repaint(); * </code> * * or * * <pre> * window.pack() * </pre> * * If this is not done, the changes in the layout will not be seen until the * container is resized. * * @param i zero-based index of row to set. If this parameter is not * valid, an ArrayOutOfBoundsException will be thrown. * @param size height of the row. This parameter cannot be null. * * @see getRow */ public void setRow (int i, double size) { // Make sure size is valid if ((size < 0.0) && (size != FILL) && (size != PREFERRED) && (size != MINIMUM)) { size = 0.0; } // Copy new size rowSpec[i] = size; // Indicate that the cell sizes are not known dirty = true; } /** * Gets the sizes of columns in this layout. * * @return widths of each of the columns * * @see setColumn */ public double [] getColumn () { // Copy columns double column[] = new double[columnSpec.length]; System.arraycopy (columnSpec, 0, column, 0, column.length); return column; } /** * Gets the height of a single row in this layout. * * @return height of the requested row * * @see setRow */ public double [] getRow () { // Copy rows double row[] = new double[rowSpec.length]; System.arraycopy (rowSpec, 0, row, 0, row.length); return row; } /** * Gets the width of a single column in this layout. * * @param i zero-based index of row to get. If this parameter is not valid, * an ArrayOutOfBoundsException will be thrown. * * @return width of the requested column * * @see setRow */ public double getColumn (int i) { return columnSpec[i]; } /** * Gets the sizes of a row in this layout. * * @param i zero-based index of row to get. If this parameter is not valid, * an ArrayOutOfBoundsException will be thrown. * * @return height of each of the requested row * * @see setRow */ public double getRow (int i) { return rowSpec[i]; } /** * Gets the number of columns in this layout. * * @return the number of columns */ public int getNumColumn () { return columnSpec.length; } /** * Gets the number of rows in this layout. * * @return the number of rows */ public int getNumRow () { return rowSpec.length; } //****************************************************************************** //** Insertion/Deletion methods *** //****************************************************************************** /** * Inserts a column in this layout. All components to the right of the * insertion point are moved right one column. The container will need to * be laid out after this method returns. See <code>setColumn</code>. * * @param i zero-based index at which to insert the column. * @param size size of the column to be inserted * * @see setColumn * @see deleteColumn */ public void insertColumn (int i, double size) { // Make sure position is valid if ((i < 0) || (i > columnSpec.length)) throw new IllegalArgumentException ("Parameter i is invalid. i = " + i + ". Valid range is [0, " + columnSpec.length + "]."); // Make sure column size is valid if ((size < 0.0) && (size != FILL) && (size != PREFERRED) && (size != MINIMUM)) { size = 0.0; } // Copy columns double column[] = new double[columnSpec.length + 1]; System.arraycopy (columnSpec, 0, column, 0, i); System.arraycopy (columnSpec, i, column, i + 1, columnSpec.length - i); // Insert column column[i] = size; columnSpec = column; // Move all components that are to the right of new row ListIterator iterator = list.listIterator(0); while (iterator.hasNext()) { // Get next entry Entry entry = (Entry) iterator.next(); // Is the first column to the right of the new column if (entry.col1 >= i) // Move first column entry.col1++; // Is the second column to the right of the new column if (entry.col2 >= i) // Move second column entry.col2++; } // Indicate that the cell sizes are not known dirty = true; } /** * Inserts a row in this layout. All components below the insertion point * are moved down one row. The container will need to be laid out after this * method returns. See <code>setRow</code>. * * @param i zero-based index at which to insert the column. * @param size size of the row to be inserted * * @see setRow * @see deleteRow */ public void insertRow (int i, double size) { // Make sure position is valid if ((i < 0) || (i > rowSpec.length)) throw new IllegalArgumentException ("Parameter i is invalid. i = " + i + ". Valid range is [0, " + rowSpec.length + "]."); // Make sure row size is valid if ((size < 0.0) && (size != FILL) && (size != PREFERRED) && (size != MINIMUM)) { size = 0.0; } // Copy rows double row[] = new double[rowSpec.length + 1]; System.arraycopy (rowSpec, 0, row, 0, i); System.arraycopy (rowSpec, i, row, i + 1, rowSpec.length - i); // Insert row row[i] = size; rowSpec = row; // Move all components that are below the new row ListIterator iterator = list.listIterator(0); while (iterator.hasNext()) { // Get next entry Entry entry = (Entry) iterator.next(); // Is the first row to the right of the new row if (entry.row1 >= i) // Move first row entry.row1++; // Is the second row to the right of the new row if (entry.row2 >= i) // Move second row entry.row2++; } // Indicate that the cell sizes are not known dirty = true; } /** * Deletes a column in this layout. All components to the right of the * deletion point are moved left one column. The container will need to * be laid out after this method returns. See <code>setColumn</code>. * * @param i zero-based index of column to delete * * @see setColumn * @see deleteColumn */ public void deleteColumn (int i) { // Make sure position is valid if ((i < 0) || (i >= columnSpec.length)) throw new IllegalArgumentException ("Parameter i is invalid. i = " + i + ". Valid range is [0, " + (columnSpec.length - 1) + "]."); // Copy columns double column[] = new double[columnSpec.length - 1]; System.arraycopy (columnSpec, 0, column, 0, i); System.arraycopy (columnSpec, i + 1, column, i, columnSpec.length - i - 1); // Delete column columnSpec = column; // Move all components that are to the right of row deleted ListIterator iterator = list.listIterator(0); while (iterator.hasNext()) { // Get next entry Entry entry = (Entry) iterator.next(); // Is the first column to the right of the new column if (entry.col1 >= i) // Move first column
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -