SwingX JXTable Boolean column is different in color

I have a little problem with SwingX components.

In my Im application using JXTable and on the table I register MouseOver ColorHighlighter. The table model defines two columns; String column and Boolean column. By default, rendering a Boolean column in JXTable is CheckBoxes. Now the problem is when the mouse moves along the lines, ColorHighlighter selects columns of different colors; the boolean column is darker than the String column. In the example you can see the behavior.

I want all columns to be highlighted in the same color.

Does anyone have an idea to solve a 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; } } } 

code>

+4
source share
2 answers

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

+1
source

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

+1
source

Source: https://habr.com/ru/post/1343901/


All Articles