He tried the naive approach first. He overrode the getColumnClass() method in his TableModel to return Integer.class for the quantity and Double.class for the price. Swing, in its automatic mercy, should have right-aligned numbers. It did not. The numbers remained left-aligned, mocking him.
Simon had been staring at the same screen for four hours. The coffee in his mug had long gone cold, forming a thin, oily film on top. Around him, the open-plan office hummed with the quiet chaos of a startup on the edge of a deadline. But for Simon, the world had shrunk to a single, infuriating component: a JTable in a Java Swing application.
It wasn't modern. It wasn't glamorous. But when Lena saw the working table the next morning, her simple "Oh, that looks perfect" was the only reward he needed.
The window appeared. The JTable loaded. He stared.
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.
That’s when the real descent began. The "Text Alignment And Column Wrapping" part of his search query became an obsession.
He dug into the sacred texts—the Java Tutorials from Oracle, circa 2003. He found the ancient spell: a custom TextAreaRenderer that implements TableCellRenderer and overrides getTableCellRendererComponent() . Inside, you set the text on a JTextArea , set the setWrapStyleWord(true) , setLineWrap(true) , and then—this was the arcane part—you had to manually calculate the preferred height of the JTextArea based on the column width and the font metrics.
He tried the naive approach first. He overrode the getColumnClass() method in his TableModel to return Integer.class for the quantity and Double.class for the price. Swing, in its automatic mercy, should have right-aligned numbers. It did not. The numbers remained left-aligned, mocking him.
Simon had been staring at the same screen for four hours. The coffee in his mug had long gone cold, forming a thin, oily film on top. Around him, the open-plan office hummed with the quiet chaos of a startup on the edge of a deadline. But for Simon, the world had shrunk to a single, infuriating component: a JTable in a Java Swing application.
It wasn't modern. It wasn't glamorous. But when Lena saw the working table the next morning, her simple "Oh, that looks perfect" was the only reward he needed.
The window appeared. The JTable loaded. He stared.
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.
That’s when the real descent began. The "Text Alignment And Column Wrapping" part of his search query became an obsession.
He dug into the sacred texts—the Java Tutorials from Oracle, circa 2003. He found the ancient spell: a custom TextAreaRenderer that implements TableCellRenderer and overrides getTableCellRendererComponent() . Inside, you set the text on a JTextArea , set the setWrapStyleWord(true) , setLineWrap(true) , and then—this was the arcane part—you had to manually calculate the preferred height of the JTextArea based on the column width and the font metrics.
