SwingX JXTable 布尔列在突出显示时具有不同的颜色
我对 SwingX 组件有一个小问题。
在我的应用程序中,我使用 JXTable,并在桌子上注册了 MouseOver ColorHighlighter。表的模型定义了两列;一个字符串列和一个布尔列。 JXTable 中布尔列的默认呈现器是复选框。现在的问题是,当鼠标在行上移动时,ColorHighlighter 以不同的颜色突出显示列;布尔列比字符串列更暗。 在示例中您可以看到该行为。
我希望所有列都以相同的颜色突出显示。
有人有解决问题的想法吗?
<代码>
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;
}
}
}
<代码>
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;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在最新版本(SwingX 1.6.2)中运行该程序。您应该看到两列具有相同的颜色。
Run the program in the latest version (SwingX 1.6.2). And you should see the same color for both columns.
如果删除 Alpha,则两列的突出显示颜色相同。
If you remove the alpha, the highlight color is the same for both columns.