本文整理匯總了Java中javax.swing.table.DefaultTableModel.setDataVector方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultTableModel.setDataVector方法的具體用法?Java DefaultTableModel.setDataVector怎麽用?Java DefaultTableModel.setDataVector使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.table.DefaultTableModel
的用法示例。
在下文中一共展示了DefaultTableModel.setDataVector方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateTableFromEditor
import javax.swing.table.DefaultTableModel; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void updateTableFromEditor() {
synchronized (this) {
if (updateing) {
return;
}
updateing = true;
DefaultTableModel dtm = (DefaultTableModel) propertyTable.getModel();
Vector columns = new Vector(2);
Vector values = new Vector();
columns.add(dtm.getColumnName(0));
columns.add(dtm.getColumnName(1));
if (value != null) {
for (String key : value.stringPropertyNames()) {
Vector row = new Vector(2);
row.add(key);
row.add(value.getProperty(key, ""));
values.add(row);
}
}
dtm.setDataVector(values, columns);
updateing = false;
}
}
示例2: doImport
import javax.swing.table.DefaultTableModel; //導入方法依賴的package包/類
/**
* This method imports data from a CSV file
*/
public void doImport(){
if (this.getFile()==null) {
System.err.println("No CSV file specified for import!");
}else{
CsvFileReader fileReader = new CsvFileReader(this.separator);
Vector<Vector<Object>> importedData = fileReader.importData(this.file);
if(importedData != null){
Vector<Object> headlines;
if(this.hasHeadlines()){
headlines = importedData.get(0);
importedData.remove(0);
}else{
headlines = new Vector<Object>();
int columnCount = importedData.get(0).size();
for(int i=0; i<columnCount; i++){
headlines.addElement("Column "+(i+1));
}
}
DefaultTableModel tableModel = new DefaultTableModel();
tableModel.setDataVector(importedData, headlines);
this.setTableModel(tableModel);
}
}
}
示例3: deletecol
import javax.swing.table.DefaultTableModel; //導入方法依賴的package包/類
/**
* Delete a single column from the table model
*
* @param table target table
* @param col target column
* @deprecated
*/
static void deletecol(JTable table, int col) {
DefaultTableModel tmodel = (DefaultTableModel) table.getModel();
DefaultTableModel tmodel1 = new DefaultTableModel();
TableModelListener[] listeners = tmodel.getTableModelListeners();
Vector<?> v = tmodel.getDataVector();
Vector<?> v1 = newvector(v, col);
tmodel1.setDataVector(v1, getColumnIdentifiersremovecol(table, col));
table.setModel(tmodel1);
for (TableModelListener l : listeners) {
tmodel1.addTableModelListener(l);
}
}
示例4: addcol
import javax.swing.table.DefaultTableModel; //導入方法依賴的package包/類
/**
* Adding column is done by creating new model by modifying older one.<p>
*
* Insert new column if column is outside the <code>limit</code> Adds new
* column if selected column inside the <code>limit</code>[email protected] _table
* target table
*
* @param limit the range to avoid inserting
*/
static void addcol(JTable table, int limit) {
try {
int sc = table.getSelectedColumn();
if (sc < limit - 1) {
sc = table.getColumnCount() - 1;
}
DefaultTableModel tableM = (DefaultTableModel) table.getModel();
DefaultTableModel tableM1 = new DefaultTableModel();
TableModelListener[] listeners = tableM.getTableModelListeners();
tableM1.setDataVector(newvectoraddcol(tableM.getDataVector(), sc), getColumnIdentifiersaddcol(sc + 1, table));
table.setModel(tableM1);
for (TableModelListener l : listeners) {
tableM1.addTableModelListener(l);
}
} catch (Exception ex) {
Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例5: openScheduleInTable
import javax.swing.table.DefaultTableModel; //導入方法依賴的package包/類
private void openScheduleInTable(ScheduleJTable table,DefaultTableModel data, Schedule schedule) {
if(schedule!=null) {
data.setDataVector(schedule.toStringArray(), selectedTrainColumnNames);
}
data.fireTableDataChanged();
table.schedule = schedule;
}
示例6: convertValueToTableModel
import javax.swing.table.DefaultTableModel; //導入方法依賴的package包/類
private DefaultTableModel convertValueToTableModel(String value) {
String[] tokens = StringUtil.split(value, ',');
DefaultTableModel tableModel =
new DefaultTableModel() {
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return (columnIndex == 1 && rowIndex == 0) || columnIndex == 2;
}
};
Object[] columnNames = new Object[]{"Option", "Min", "Max", "Color"};
Object[][] data = new Object[3][4];
for (int i = 0; i < tokens.length; i++) {
String token = tokens[i];
String[] optionAndIntervalWithColor = StringUtil.split(token, '=');
String option = optionAndIntervalWithColor[0];
String[] intervalWithColor = StringUtil.split(optionAndIntervalWithColor[1], "->");
IntervalValue<Color> interval = IntervalValue.valueOf(intervalWithColor[0]);
try {
interval.value = Color.valueOf(intervalWithColor[1]);
} catch (IllegalArgumentException skip) {
interval.value = Color.valueOf("#FFFFFFFF");
}
int index = ORDERED_OPTIONS.indexOf(option);
data[index] = new String[]{option, interval.from + "", interval.to + "", interval.value.getValue() + ""};
}
// >> quick fix
data[0][0] = ORDERED_OPTIONS.get(0);
data[1][0] = ORDERED_OPTIONS.get(1);
data[2][0] = ORDERED_OPTIONS.get(2);
// <<
tableModel.setDataVector(data, columnNames);
return tableModel;
}
示例7: refreshTableModel
import javax.swing.table.DefaultTableModel; //導入方法依賴的package包/類
/**
* Refreshes the local table model by reloading the data from the DynForm.
*/
@SuppressWarnings("unchecked")
public void refreshTableModel() {
int rowIndexSelected = this.getSelectedRow();
DefaultTableModel dtm = (DefaultTableModel) this.getModel();
if (dtm.getColumnCount()==0) {
// --- Create a new table model ---------------
Vector<String> columnNames = new Vector<String>();
columnNames.add(" ");
columnNames.add(" ");
dtm = this.getTableModel();
dtm.setDataVector(this.getDataVector(), columnNames);
this.setModel(dtm);
this.setRendererAndEditors();
this.setRowSorter(this.getMyRowSorter());
} else {
// --- Exchange or re-new the data model ------
DynTableDataVector newDataVector = new DynTableDataVector(this.dynForm);
if (newDataVector.isEqualStructure(dtm.getDataVector())==false) {
// --- exchange data completely -----------
this.setDataVector(newDataVector);
dtm.getDataVector().removeAllElements();
dtm.getDataVector().addAll(this.getDataVector());
dtm.fireTableDataChanged();
this.setRowSorter(this.getMyRowSorter());
} else {
// --- Same structure! --------------------
// --- => Just exchange different values --
// // --- THIS IS JUST A BACKUP SOLUTION -----
// for (int i=0; i < this.getDataVector().size(); i++) {
//
// Object objectThisRow = this.getDataVector().get(i);
// Vector<Object> rowThis = (Vector<Object>) objectThisRow;
// DynType dynTypeThis = (DynType) rowThis.get(0);
// JComponent jCompThis = dynTypeThis.getFieldDisplay();
//
// Object objectNewRow = newDataVector.get(i);
// Vector<Object> rowNew = (Vector<Object>) objectNewRow;
// DynType dynTypeNew = (DynType) rowNew.get(0);
// JComponent jCompNew = dynTypeNew.getFieldDisplay();
//
// if ((jCompThis!=null && jCompNew!=null) && jCompThis.getClass().getName().equals(jCompNew.getClass().getName())==true) {
// if (jCompThis instanceof JTextField) {
// ((JTextField) jCompThis).setText(((JTextField) jCompNew).getText());
// } else if (jCompThis instanceof JCheckBox) {
// ((JCheckBox) jCompThis).setSelected(((JCheckBox) jCompNew).isSelected());
// }
// }
//
// }
dtm.fireTableDataChanged();
}
}
// --- Set new selection --------------------------
int rowCount = this.getRowCount();
if (rowIndexSelected>(rowCount-1)) {
this.setRowSelectionInterval(rowCount-1, rowCount-1);
} else if (rowIndexSelected>-1) {
this.setRowSelectionInterval(rowIndexSelected, rowIndexSelected);
}
}