Java Utililty Methods JTable Row

List of utility methods to do JTable Row

Description

The list of methods to do JTable Row are organized into topic(s).

Method

booleancheckRow(DefaultTableModel table, List data, int row)
Checks if data could be written on the table starting from row.
String[] locations = data.get(1);
String[] time = data.get(2);
int rows = table.getRowCount();
int cols = table.getColumnCount();
int counter = 0;
for (int i = 0; i < locations.length; i++) {
    if (i - 1 >= 0) {
        counter += Integer.parseInt(time[i - 1].trim());
...
voidclearAllRows(JTable table)
clear All Rows
DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
int rowCount = tableModel.getRowCount();
for (int i = 0; i < rowCount; i++) {
    tableModel.removeRow(rowCount - i - 1);
booleancontains(int row, TableModel model)
contains
if (model == null) {
    return false;
if (row < 0) {
    return false;
return row < model.getRowCount();
voidcopyRows(JTable table)
copy Rows
StringBuffer sb = new StringBuffer();
for (int iSelectedRow : table.getSelectedRows()) {
    sb.append(getColumnData(table, iSelectedRow));
    sb.append("\n");
final StringSelection stsel = new StringSelection(sb.toString());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stsel, stsel);
StringcreateDBXMLFile(JTable table, String docField, String rowField, Connection con, boolean reuseConnection, String driver, String dsn, String user, String password, String tableName, String whereString, String orderByString, String groupByString, boolean convertCharsToEntites)
create DBXML File
String rootElement = docField;
String elementName = rowField;
StringBuffer toWrite = new StringBuffer("");
toWrite.append("<?xml version=\"1.0\" encoding=\"" + "UTF-8" + "\"?>\n");
toWrite.append("<" + rootElement + ">");
Vector data = getRowsFromDatabase(con, 0, reuseConnection, driver, dsn, user, password, tableName,
        whereString, orderByString, groupByString);
data = removeBadChars(data, convertCharsToEntites);
...
ObjectcreateThrowableMessage(Throwable t)
create Throwable Message
JPanel panel = new JPanel(new BorderLayout(12, 12));
panel.add(new JLabel(t.getLocalizedMessage()), BorderLayout.NORTH);
JTextArea stackTrace = new JTextArea();
stackTrace.setForeground(Color.red);
stackTrace.setColumns(50);
stackTrace.setEditable(false);
stackTrace.setTabSize(4);
stackTrace.setText(toString(t));
...
voiddeleteRows(final int[] sortedRows, final List list, final AbstractTableModel model)
delete Rows
for (int i = sortedRows.length - 1; i >= 0; --i) {
    list.remove(sortedRows[i]);
model.fireTableDataChanged();
voidensureRowCount(int count, JTable table)
Method checks if the row count is greater or equal to specified count, if not - it add a row
DefaultTableModel model = (DefaultTableModel) table.getModel();
int i, j;
for (i = table.getRowCount(); i < count; ++i) {
    model.addRow(new Object[table.getColumnCount()]);
    for (j = 0; j < table.getColumnCount(); ++j)
        table.setValueAt("", i, j);
booleanfirstRowIsVoid(TableModel model)
first Row Is Void
boolean isVoid = true;
for (int colIndex = 0; colIndex < model.getColumnCount(); colIndex++) {
    if (model.getValueAt(0, colIndex) == null) {
        isVoid = true;
    } else {
        isVoid = false;
        break;
return isVoid;
intgetModelRowAtPoint(JTable table, Point point)
get Model Row At Point
int row = table.rowAtPoint(point);
return rowToModelIndex(table, row);