Is this your first time here? SwingWiki is a Java Swing Developer community site with an big archive of Swing-related usenet groups and mailing lists, but also tips, tricks and articles and book reviews written by your colleagues from around the world. If you came here through a search engine and did not find what you were looking for, make sure to check the wiki table of contents.

Shade disabled cells

Users usually expect disabled (un-editable) components to be marked with a distinctive background. For most components, that is true. However, default JTable renderer does not render uneditable cells any different than editable cells. So, shade disabled cells to make your table more user-friendly. Here is a snippet that does the work1).

class DisabledCellRenderer extends DefaultTableCellRenderer{
	public Component getTableCellRendererComponent(
		JTable table,
		Object value,
		boolean isSelected,
		boolean hasFocus,
		int row,
		int column) {
		if (table.isCellEditable(row, column)) setBackground(Color.WHITE);
		else setBackground(Color.LIGHT_GRAY);
		return super.getTableCellRendererComponent(
1) alternatively, you can make this more flexible by embedding the current renderer in a wrapper class that shades uneditable cells

Comments? Corrections? Contact us or Login to edit pages directly (registration is free and takes less than displaying a JLabel)
  best/shade_disabled_cells.txt · Last modified: 2005/02/12 17:46
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++| Ruby Resources

Sedo - Buy and Sell Domain Names and Websites project info: Statistics for project etracker� web controlling instead of log file analysis