package spikes;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

public class StringRenderer extends JLabel
        implements TableCellRenderer
{
    public StringRenderer()
    {
    }

    public Component getTableCellRendererComponent(
            JTable table, Object message,
            boolean isSelected, boolean hasFocus,
            int row, int column)
    {
        String msgText = (String) message;
        setText(msgText);
        setToolTipText(msgText.toUpperCase());
        return this;
    }
}

/**
 * This is an example of a CellRenderer that tailors the way the output is
 * displayed.
 */
class SimpleWordRenderer extends DefaultTableCellRenderer
{
    protected void setValue(Object value)
    {
        String word = (String) value;
        String name = word.toString().toUpperCase();
        // Long words get a star added to them
        if (word.length() > 9)
        {
            name = name + "*";
        }
        setToolTipText(name);
        setText(name);
    }
}
