Text Dissappears from Table

Have an issue applying a custom cell renderer to a table that I've created, unfortunately when i apply the renderer the text disappears. remove the renderer and it reappears.

I've set the foreground and background colours and set Opaque to true I've even tried setting the value again in the renderer with no luck. I think I've got all the required code below.
occupationTable = new JTable(model);
occupationTable.setDefaultRenderer(Object.class, new tableColour());

Open in new window

package renderers;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;

import dataTypes.OccupationTableModel;

public class tableColour extends JTable implements TableCellRenderer {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// public static final DefaultTableCellRenderer DEFAULT_RENDERER = new
	// DefaultTableCellRenderer();

	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {
		setOpaque(true);

		OccupationTableModel aModel = (OccupationTableModel) table.getModel();

		String Acceptence = aModel.getOccupation(rowIndex).getgeneralAcceptence();

		if (isSelected) {
			this.setForeground(Color.BLACK);
			this.setBackground(Color.BLUE);
			
		} else {
			if (Acceptence != null) {
				try {
					if (Acceptence.equals("Decline")) {
						this.setForeground(Color.BLACK);
						this.setBackground(Color.RED);
					} else {
						this.setForeground(Color.BLACK);
						this.setBackground(Color.WHITE);
					}
				} catch (Exception e) {
					System.out.println("Shit");
					e.printStackTrace();
				}
			}
			
		}
		return this;
	}

}

Open in new window

UnformattedTable.jpg
UnformattedTable.jpg
CloudStrife209Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
Strange, why your CellRenderee extends JTable?

I'd rather suggest to extend DefaultTableCellRenderer and overwrite getCompoenet methodadding colors there
0
for_yanCommented:
Look at this example of TableCellRenderer

http://www.exampledepot.com/egs/javax.swing.table/CustRend.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
for_yanCommented:
So look your class tableColour extends JTable, so when you say
return this;
in the getComponent method it actually returns an iinstance of JTable - which does not make much sense
what happend after that with your view is rather hard to imagine
0
for_yanCommented:

In fact getComponent sould return the component which will populate the cell of your table - so that would usually
be JLaebel as in the example above or JTextField - something normally lighter than JTable
0
for_yanCommented:

also look at good example here:
http://www.roseindia.net/java/example/java/swing/CustomCellRenderer.shtml

With these things it is easier to follow the exisiting pattern  - take one of the above examples -
make sure it returns the background color as you like it and it would most probably work.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.