¶Ç º¸´Â±º¿ä...


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :ÀÌÁ¾´ë 1999³â 8¿ù 10ÀÏ 16:02:59

In Reply to: JTable »ç¿ë¹ý¿¡ ´ëÇØ.... posted by ÀÌÁØ±Ô on 1999³â 8¿ù 10ÀÏ 15:36:12:

ÀÌ°Ç Á¦°¡ ¿¹Àü¿¡ Çß´ø ÇÁ·Î±×·¥Àε¥
SunÀÇ ÀÚ¹Ù Æ©Å丮¾ó¿¡ ÀÖ´Â ³»¿ëÀ» ¼öÁ¤ÇÑ °ÍÀÔ´Ï´Ù


import javax.swing.*;
import javax.swing.table.*;


/**
* Description : TableModel SubClass
* @see : DataDown
* @version : 1.0
* @auther : LJD
*/
class ListTableModel extends AbstractTableModel {
private String[] columnNames;
private Object[][] data;


public int getColumnCount() {
return columnNames.length;
}

public int getRowCount() {
return data.length;
}


public String getColumnName(int col) {
return columnNames[col];
}


public Object getValueAt(int row, int col) {
return data[row][col];
}


public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}


public boolean isCellEditable(int row, int col) {
if (col > 1) {
return false;
} else {
return true;
}
}


public void setColumnNames(String[] clsColNames) {
columnNames = clsColNames;
}


public void setDatas(Object[][] clsData) {
data = clsData;
}


public void setValueAt(Object value, int row, int col) {
if (data[0][col] instanceof Integer) {
try {
data[row][col] = new Integer((String)value);
} catch (NumberFormatException e) {
System.err.println("User attempted to enter non-integer"
+ " value (" + value
+ ") into an integer-only column.");
}
} else {
data[row][col] = value;
}
}
}


À§¿Í°°Àº Ŭ·¡½º¸¦ ¸¸µé°í main¿¡¼­


try {
jtabDocList = new JTable();
jtabDocList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
jtabDocList.setCellSelectionEnabled(true);
jtabDocList.setColumnSelectionAllowed(true);
jtabDocList.setName("DocList");
jtabDocList.setShowGrid(false);
jtabDocList.sizeColumnsToFit(JTable.AUTO_RESIZE_ALL_COLUMNS);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}


clsColNames¶ó´Â ¹è¿­¿¡ columnÀÇ titleµéÀ» ÀúÀåÇÏ°í
clsData¶ó´Â ¹è¿­¿¡´Â ½ÇÁ¦ data¸¦ ÀúÀåÇÏ°í


ListTableModel myModel = new ListTableModel();
myModel.setDatas(clsData);
myModel.setColumnNames(clsColNames);
getDocList().setModel(myModel);
getDocList().updateUI();


À§¿Í°°ÀÌ ÀÛ¼ºÇϸé JTable°¡ ¿Ï¼ºµÇ¾î È­¸é¿¡ ³ª¿À°Ô µË´Ï´Ù


µµ¿òÀÌ µÆ±â¸¦...



´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]