comparison src/name/blackcap/exifwasher/Misc.kt @ 9:0a106e9b91b4

Fix table layout; fix "select all for deletion" feature.
author David Barts <n5jrn@me.com>
date Fri, 10 Apr 2020 19:17:09 -0700
parents 88d02fa97d78
children 39b977021ea1
comparison
equal deleted inserted replaced
8:88d02fa97d78 9:0a106e9b91b4
173 * Set column width of a table. 173 * Set column width of a table.
174 */ 174 */
175 fun JTable.setColWidth(col: Int, width: Int, string: String?) { 175 fun JTable.setColWidth(col: Int, width: Int, string: String?) {
176 val FUZZ = 4 176 val FUZZ = 4
177 columnModel.getColumn(col).preferredWidth = if (string.isNullOrEmpty()) { 177 columnModel.getColumn(col).preferredWidth = if (string.isNullOrEmpty()) {
178 width + FUZZ 178 width
179 } else { 179 } else {
180 maxOf(width, graphics.fontMetrics.stringWidth(string)) + FUZZ 180 maxOf(width, graphics.fontMetrics.stringWidth(string) + FUZZ)
181 } 181 }
182 } 182 }
183 183
184 /** 184 /**
185 * Set overall width of a table. 185 * Set overall width of a table.
186 */ 186 */
187 fun JTable.setOverallWidth() { 187 fun JTable.setOverallWidth() {
188 val tcm = columnModel 188 val tcm = columnModel
189 val limit = tcm.columnCount - 1
189 var total = 0 190 var total = 0
190 for (i in 0 .. tcm.columnCount - 1) { 191 for (i in 0 .. limit) {
191 total += tcm.getColumn(i).preferredWidth 192 total += tcm.getColumn(i).preferredWidth
192 } 193 }
193 preferredSize = Dimension(total, preferredSize.height) 194 preferredSize = Dimension(total, preferredSize.height)
194 } 195 }