Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set custom row height (JTable)?

843806Apr 5 2009 — edited Apr 5 2009
Hi all.

I am using JTable with one column. I want to make some rows' height different. I implemented TableCellRenderer like this:


public class TableSampleCellRenderer extends JLabel implements TableCellRenderer {



	public TableSampleCellRenderer() {

		setOpaque(true);

	}



	public Component getTableCellRendererComponent(JTable table,

			Object value,

			boolean isSelected,

			boolean hasFocus,

			int row,

			int column) {



		if (isSelected) {

			setBackground(table.getSelectionBackground());

			setForeground(table.getSelectionForeground());

		} else {

			setBackground(table.getBackground());

			setForeground(table.getForeground());

		}


		// ... and here goes the magic ...
		if (row == 5) {

			setSize(table.getCellRect(row, column, true).width,50);

		}



		TableSampleItem tsi = (TableSampleItem) value;



		setText(tsi.getItemName());



		return this;

	}

}
Unfortunately, it does not work. Is there a way to do so?

Thank you in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 3 2009
Added on Apr 5 2009
7 comments
132 views