# HG changeset patch # User David Barts # Date 1586556576 25200 # Node ID 88d02fa97d782147e4951d8df4d93a78c3e6d449 # Parent 65d14d44bc3f2749a2d8501e232f7cdf610b35e5 Got WasherDialog table laying out somewhat sanely. diff -r 65d14d44bc3f -r 88d02fa97d78 src/name/blackcap/exifwasher/Misc.kt --- a/src/name/blackcap/exifwasher/Misc.kt Fri Apr 10 13:44:04 2020 -0700 +++ b/src/name/blackcap/exifwasher/Misc.kt Fri Apr 10 15:09:36 2020 -0700 @@ -5,8 +5,13 @@ import java.awt.Component import java.awt.Cursor +import java.awt.Dimension +import java.awt.Font +import java.awt.FontMetrics +import java.awt.Graphics import java.awt.Toolkit import javax.swing.* +import javax.swing.table.TableColumnModel import kotlin.annotation.* import kotlin.properties.ReadWriteProperty import kotlin.reflect.* @@ -163,3 +168,27 @@ setVisible(false) dispose() } + +/** + * Set column width of a table. + */ +fun JTable.setColWidth(col: Int, width: Int, string: String?) { + val FUZZ = 4 + columnModel.getColumn(col).preferredWidth = if (string.isNullOrEmpty()) { + width + FUZZ + } else { + maxOf(width, graphics.fontMetrics.stringWidth(string)) + FUZZ + } +} + +/** + * Set overall width of a table. + */ +fun JTable.setOverallWidth() { + val tcm = columnModel + var total = 0 + for (i in 0 .. tcm.columnCount - 1) { + total += tcm.getColumn(i).preferredWidth + } + preferredSize = Dimension(total, preferredSize.height) +} diff -r 65d14d44bc3f -r 88d02fa97d78 src/name/blackcap/exifwasher/WashDialog.kt --- a/src/name/blackcap/exifwasher/WashDialog.kt Fri Apr 10 13:44:04 2020 -0700 +++ b/src/name/blackcap/exifwasher/WashDialog.kt Fri Apr 10 15:09:36 2020 -0700 @@ -83,16 +83,12 @@ } else { myTable.run { model = MyTableModel(tableData, COLUMN_NAMES) - columnModel.run { - getColumn(0).run { - preferredWidth = 10 - maxWidth = 850000000 /* xxx - don't ask */ - } - getColumn(1).preferredWidth = 100 /* key name */ - getColumn(2).preferredWidth = 5 /* type */ - getColumn(3).preferredWidth = 200 /* value */ - } - autoResizeMode = JTable.AUTO_RESIZE_LAST_COLUMN + autoResizeMode = JTable.AUTO_RESIZE_OFF + setColWidth(0, 0, COLUMN_NAMES[0]) + setColWidth(1, 180, null) + setColWidth(2, 72, "Undefined") + setColWidth(3, 720, null) + setOverallWidth() } setVisible(true) } @@ -200,7 +196,7 @@ alignmentX = JScrollPane.LEFT_ALIGNMENT border = BorderFactory.createEmptyBorder(BW, BW, BW, BW) verticalScrollBarPolicy = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS - horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER + horizontalScrollBarPolicy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS preferredSize = Dimension(WIDTH, HEIGHT) background = Application.mainFrame.background }) @@ -215,6 +211,7 @@ add(resetButton) add(Box.createHorizontalGlue()) add(cancelButton) + add(Box.createHorizontalStrut(BW2)) add(washButton) }) }