Java Swing - Jtable Text Alignment And Column W... New! Jun 2026
He looked at the Description column. A long sentence stretched across multiple lines, wrapping neatly at the column boundary, pushing the row taller just enough to contain it. The next row, with a short description, was shorter. The row heights were dynamic. Perfect. Beautiful.
Smart applications remember user column adjustments. Store widths in Preferences :
// Make the frame visible frame.setVisible(true); Java Swing - JTable Text Alignment And Column W...
A JTable is a component that displays data in a table format, with rows and columns. It is a powerful component that allows you to display large amounts of data in a compact and organized way. JTable is often used in conjunction with other components, such as JScrollPane , to provide a scrollable view of the data.
// Calculate preferred height int height = (int) getPreferredSize().getHeight(); if (table.getRowHeight(row) != height) table.setRowHeight(row, height); He looked at the Description column
He resized the Description column by dragging the header. The text rewrapped in real-time , adjusting to the new width like water finding its level.
Once you have the renderer class, attach it to specific columns: The row heights were dynamic
// Set text alignment for each column DefaultTableCellRenderer leftAlignedRenderer = new DefaultTableCellRenderer(); leftAlignedRenderer.setHorizontalAlignment(JLabel.LEFT); table.getColumnModel().getColumn(0).setCellRenderer(leftAlignedRenderer);