Skip to main content

JXTable Boolean column have different color on highlight

2 replies [Last post]
Seffel
Offline
Joined: 2011-03-16
Points: 0

Hi everybody!

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;

    }

  }

THX Seffel

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

The screenshot is not coming through and I have run the test case and don't see an issue. I also added a alternating-stripe to ensure that the color blending was happening correctly and it appears to work as expected. Are you using a particular Look and Feel?

Karl

Seffel
Offline
Joined: 2011-03-16
Points: 0

Thx for your replay.
I have found the problem.
In the Example I used the older swingX 1.0 version and in this version the columns have different colors. Now I tryed the latest version of swingX 1.6.2 and both columns have the same color.
greetz Seffel