5

I have a little problem with SwingX Components.

In my Application I’m using a JXTable and on the table I register a MouseOver ColorHighlighter. The model of the table defines two columns; a String column and a Boolean column. The default renderers of a Boolean column in a JXTable are CheckBoxes. Now the Problem is when the Mouse moves over the rows the ColorHighlighter highlights the columns in different colors; the Boolean column is darker then the String column. In the Example you can see the behavior.

I want that all columns were highlighted in the same color.

Have anyone an idea to solve the problem?



import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;

import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.ColorHighlighter;
import org.jdesktop.swingx.decorator.HighlightPredicate;


public class BooleanHighlighterDemo
{
  public static void main( String args[] )
  {
    JFrame frame = new JFrame( "Boolean Highlighter" );
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    JXTable table = new JXTable( new BooleanTableModel() );

    //Add ColorHighlighter
    table.addHighlighter( new ColorHighlighter( HighlightPredicate.ROLLOVER_ROW,
        new Color( 0x330000ff, true ), Color.BLACK ) );

    frame.add( new JScrollPane( table ), BorderLayout.CENTER );
    frame.setSize( 400, 150 );
    frame.setVisible( true );
  }
}

class BooleanTableModel extends DefaultTableModel
{
  public BooleanTableModel()
  {
    super( new Object[][]{ { "1", Boolean.TRUE }, { "2", Boolean.TRUE }, { "3", Boolean.FALSE },
        { "4", Boolean.TRUE }, { "5", Boolean.FALSE } }, new String[]{ "Number", "Boolean" } );
  }

  @Override
  public Class<?> getColumnClass( int columnIndex )
  {
    switch ( columnIndex )
    {
      case 0:
        return String.class;

      case 1:
        return Boolean.class;

      default :
        return Object.class;
    }
  }
}

skaffman
  • 398,947
  • 96
  • 818
  • 769
Seffel
  • 397
  • 2
  • 14
  • I ran your example and I get the same color for both columns. – jzd Mar 16 '11 at 11:35
  • After your Comment I checked the latest version of swingX 1.6.2 out and in this version both columns have the same color. It seems that the Bug is already fixed. Thank you ! – Seffel Mar 16 '11 at 14:08
  • I should have mentioned I used 1.6.2, I will create an answer that specifies this. – jzd Mar 16 '11 at 14:13

2 Answers2

2

Run the program in the latest version (SwingX 1.6.2). And you should see the same color for both columns.

jzd
  • 23,473
  • 9
  • 54
  • 76
1

If you remove the alpha, the highlight color is the same for both columns.

z7sg Ѫ
  • 3,153
  • 1
  • 23
  • 35