开发者

SwingX JXTable Boolean column have different color on highlight

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?


SwingX JXTable Boolean column have different color on highlight


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.Co开发者_开发百科lorHighlighter;
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;
    }
  }
}


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜