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

📄 col3_sel1_tablemodel.java

📁 导出ORACLE数据库对象DDL语句的程序
💻 JAVA
字号:
package com.icbcsdc.ddlexp.ui.model;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;

/*
 * 创建日期 2004-9-7
 *
 * 更改所生成文件模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */

/**
 * @author youhx
 *---------------------------tableModel说明-----------------
 *---------------------------使用前必看!---------------------
 *
 *1.表总共只有三列
 *2.第一、二列为普通列,第三列为选项框
 *3.第一、二列不可编辑,第三列可编辑
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */

public	class Col3_Sel1_TableModel extends AbstractTableModel {
		int colLength=0;
		int rowLength=0;
//		static final int DEFAULT_ROWS=3; 
		static final int DEFAULT_COLS=100;
		String[] columnNames = new String[DEFAULT_COLS];

		Object[][] data1={{"","",new Boolean(false)}};
		Object[][] data ={{"","",new Boolean(false)}};


	
		public Col3_Sel1_TableModel(String[] columns){
			if(columns==null) return;
			colLength=columns.length;
			columnNames=new String[colLength];
			for(int i=0;i<colLength;i++){
				columnNames[i]=""+columns[i];
			}
		

		}
	

	
		public int getColumnCount() {
			if(columnNames==null) return 0;
			return colLength;
		}

		public int getRowCount() {
			if(data==null) return 0;
			return rowLength;
		}

		public String getColumnName(int col) {
			if(col<0||col>=columnNames.length) return "";
			return columnNames[col];
		}

		public Object getValueAt(int row, int col) {
			if(data==null) return null;	
			else return data[row][col];
			//else return data1[row][col];
		}

		/*
		 * JTable uses this method to determine the default renderer/
		 * editor for each cell.  If we didn't implement this method,
		 * then the last column would contain text ("true"/"false"),
		 * rather than a check box.
		 */
		public Class getColumnClass(int c) {
			return (data1[0][c]).getClass();
		}

		/*
		 * Don't need to implement this method unless your table's
		 * editable.
		 */
		public boolean isCellEditable(int row, int col) {
			//Note that the data/cell address is constant,
			//no matter where the cell appears onscreen.
			if(col <= 1)
				return false;
			else
				return true;
		}

		/*
		 * Don't need to implement this method unless your table's
		 * data can change.
		 */
		public void setValueAt(Object value, int row, int col) {
			/*if (DEBUG) {
				System.out.println("Setting value at " + row + "," + col
								   + " to " + value
								   + " (an instance of "
								   + value.getClass() + ")");
			}*/
			/*if(row<0||row>=rowLength) return;
			if(col<0||col>=colLength) return;*/

			if (data[0][col] instanceof Integer) {
				//If we don't do something like this, the column
				//switches to contain Strings.
				//XXX: See TableEditDemo.java for a better solution!!!
				try {
					data[row][col] = new Integer((String)value);
				} catch (NumberFormatException e) {
					if (SwingUtilities.isEventDispatchThread()) {
						/*JOptionPane.showMessageDialog(TableDemo.this,
							"The \"" + getColumnName(col)
							+ "\" column accepts only integer values.");*/
					} else {
						System.err.println("User attempted to enter non-integer"
									   + " value (" + value
									   + ") into an integer-only column.");
					}
				}
			} else {
				data[row][col] = value;
			}

			/*if (DEBUG) {
				System.out.println("New value of data:");
				printDebugData();
			}*/
		}

		private void printDebugData() {
			int numRows = getRowCount();
			int numCols = getColumnCount();

			for (int i=0; i < numRows; i++) {
				System.out.print("    row " + i + ":");
				for (int j=0; j < numCols; j++) {
					System.out.print("  " + data[i][j]);
				}
				System.out.println();
			}
			System.out.println("--------------------------");
		}
		/**
		 * @return
		 */
		public String[] getColumnNames() {
			return columnNames;
		}

		/**
		 * @return
		 */
		public Object[][] getData() {
			return data;
		}

		/**
		 * @param strings
		 */
		public void setColumnNames(String[] strings) {
			colLength=strings.length;
			columnNames = null;
			columnNames=new String[colLength];
			for(int i=0;i<colLength;i++){
				columnNames[i]=""+strings[i];
			}
		}

		/**
		 * @param objects
		 */
		public void setData(Object[][] objects) {
			data=null;
			rowLength=0;
			if(objects==null){
				fireTableStructureChanged(); 
				return;
			} 
			rowLength=objects.length;
			data=new Object[rowLength][colLength];
			//data=objects;
			for(int row=0;row<rowLength;row++){
				for(int col=0;col<colLength;col++)
					data[row][col]=(objects[row][col]);
			}
			fireTableStructureChanged(); 
		}
	
	

	}



⌨️ 快捷键说明

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