本文整理汇总了Java中javax.swing.table.DefaultTableModel.addTableModelListener方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultTableModel.addTableModelListener方法的具体用法?Java DefaultTableModel.addTableModelListener怎么用?Java DefaultTableModel.addTableModelListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.table.DefaultTableModel
的用法示例。
在下文中一共展示了DefaultTableModel.addTableModelListener方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: QueryBuilderGraphFrame
import javax.swing.table.DefaultTableModel; //导入方法依赖的package包/类
public QueryBuilderGraphFrame(
QueryBuilder queryBuilder,
QueryBuilderInputTable queryBuilderInputTable,
JEditorPane sqlTextArea,
DefaultTableModel resultTableModel)
{
super(new BorderLayout());
Log.getLogger().entering("QueryBuilderGraphFrame", "constructor"); // NOI18N
_queryBuilder = queryBuilder;
_queryBuilderInputTable = queryBuilderInputTable;
_inputTableModel = (DefaultTableModel) _queryBuilderInputTable.getModel();
_sqlTextArea = sqlTextArea;
_resultTableModel = resultTableModel;
// Listen for events in the input table (column list)
// Unfortunately, this gets triggered with every change to the model.
// We need a way to make a group of changes to the input table, then invoke the
// listener once at the end.
_inputTableModel.addTableModelListener(this);
// Get a list of tables in the DB
JMenu menu, subMenu;
JMenuItem menuItem;
// Create three listeners
_fsl = new FrameSelectionListener();
// _fcl = new FrameComponentListener();
_cl = new CompListener();
// Create two popup menus
_backgroundPopup = createBackgroundPopup();
_tableTitlePopup = createTableTitlePopup();
// Add listener to components that can bring up popup menus.
// Create a listener that will bring up background menu
// MouseListener backgroundPopupListener = new BackgroundPopupListener();
// Add it as listener
// _graph.addMouseListener(backgroundPopupListener);
// _desktopPane.addMouseListener(backgroundPopupListener);
// _desktopScrollPane.addMouseListener(backgroundPopupListener);
// Create a new listener for noticing graph selection
// _graph.addGraphSelectionListener(new GraphSelListener());
// Add the JScrollPane to the QueryBuilderGraphFrame
// this.add(_desktopScrollPane,BorderLayout.CENTER);
// Make the GraphFrame visible
setVisible(true);
// _dropTarget = new DropTarget(_queryBuilder.getQueryBuilderPane()._qbSceneView,
// DnDConstants.ACTION_COPY_OR_MOVE, this);
}
示例4: setUpMacrosTable
import javax.swing.table.DefaultTableModel; //导入方法依赖的package包/类
public void setUpMacrosTable() {
final DefaultTableModel tableModel = new DefaultTableModel(new Object[]{"Macro", "For string", ""}, 0);
macrosTable.setModel(tableModel);
macrosTable.getColumnModel().getColumn(2).setResizable(false);
macrosTable.getColumnModel().getColumn(2).setPreferredWidth(20);
macrosTable.getColumnModel().getColumn(2).setMaxWidth(20);
macrosTable.getColumnModel().getColumn(2).setMinWidth(20);
for (int i = 0; i < grammar.macros.size(); i++) {
tableModel.addRow(new Object[]{grammar.macros.get(i).getKey(), grammar.macros.get(i).getValue(), "-"});
}
tableModel.addRow(new Object[]{"", "", "+"});
ButtonColumn b = new ButtonColumn(macrosTable, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
JTable table = (JTable) e.getSource();
int modelRow = Integer.valueOf(e.getActionCommand());
if (modelRow < grammar.macros.size()) {
grammar.removeMacro(modelRow);
((DefaultTableModel) table.getModel()).removeRow(modelRow);
for (Graph graph : grammar.getGraphs().values())
for (GraphNode gn : graph.getGraphNodes().values())
graphEditor.renderingInfos.get(gn).formatDirty = true;
graphEditor.updateUI();
} else {
table.getModel().setValueAt("-", modelRow, 2);
grammar.macros.add(null);
((DefaultTableModel) table.getModel()).addRow(new Object[]{"", "", "+"});
}
}
}, 2);
tableModel.addTableModelListener(new TableModelListener() {
@Override
public void tableChanged(TableModelEvent tableModelEvent) {
if (tableModelEvent.getColumn() == 2 || tableModelEvent.getColumn() == -1)
return;
int row = tableModelEvent.getLastRow();
if (row == tableModel.getRowCount() - 1) {
grammar.macros.add(null);
tableModel.setValueAt("-", row, 2);
((DefaultTableModel) tableModel).addRow(new Object[]{"", "", "+"});
}
if (tableModel.getValueAt(row, 0).toString().trim().isEmpty() || tableModel.getValueAt(row, 1).toString().trim().isEmpty())
grammar.macros.set(row, null);
else
grammar.macros.set(row, new Pair<String, String>(tableModel.getValueAt(row, 0).toString(), tableModel.getValueAt(row, 1).toString()));
}
});
}