Last active
March 27, 2024 17:17
-
-
Save rubenquadros/8259f9a02be51cd136fe57a67b272bc8 to your computer and use it in GitHub Desktop.
Package table model to display in a JTable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PackageTableModel( | |
private val packages: MutableList<String> | |
) : AbstractTableModel() { | |
override fun getRowCount(): Int { | |
return packages.size | |
} | |
override fun getColumnCount(): Int { | |
return 1 //only 1 column | |
} | |
override fun getValueAt(rowIndex: Int, columnIndex: Int): Any { | |
return packages.elementAtOrElse(rowIndex) { "" } | |
} | |
override fun getColumnName(column: Int): String { | |
return "Packages" | |
} | |
override fun isCellEditable(rowIndex: Int, columnIndex: Int): Boolean { | |
return true | |
} | |
override fun setValueAt(aValue: Any?, rowIndex: Int, columnIndex: Int) { | |
packages[rowIndex] = aValue.toString() | |
} | |
fun addRow(value: String, rowIndex: Int) { | |
packages.add(rowIndex, value) | |
setValueAt(value, rowIndex, 1) | |
} | |
fun removeRow(firstRow: Int, lastRow: Int, rowIndex: Int) { | |
packages.removeAt(rowIndex) | |
fireTableRowsDeleted(firstRow, lastRow) | |
} | |
fun updateRow(rowIndex: Int, value: String) { | |
setValueAt(value, rowIndex, 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment