有趣:-)
- 一般不工作,因为的CellRendererPane不尊重组件的Visible属性 - 它戳它始终。但是:如果将实际提供者包装到WrappingProvider中,然后将该包装组件设置为不可见,则可以在SwingX中工作。
一个片段,只是作为证明的概念
table.getColumn(1).setCellRenderer(new DefaultTableRenderer(
new WrappingProvider(IconValues.NONE, new ButtonProvider(), false) {
@Override
protected void configureState(CellContext context) {
super.configureState(context);
rendererComponent.getComponent().setVisible(context.getRow() != 5);
}
}
));
在另一方面,供应商是不在定制上下文相关的配置堵的地方。这应该在荧光笔中完成,如f.i.在
AbstractHighlighter highlighter = new AbstractHighlighter(HighlightPredicate.EVEN) {
@Override
protected Component doHighlight(Component component,
ComponentAdapter adapter) {
((WrappingIconPanel) component).getComponent().setVisible(false);
return component;
}
@Override
protected boolean canHighlight(Component component,
ComponentAdapter adapter) {
return component instanceof WrappingIconPanel;
}
};
table.addHighlighter(highlighter);
不按预期工作(按钮始终隐藏),因为它不是保证在提供程序中重置的属性之一。没有什么能阻止自定义提供延长这些保障,像
table.getColumn(1).setCellRenderer(new DefaultTableRenderer(
// custom wrappingProvider which guarantees the reset of visible
// property of the wrapped component
new WrappingProvider(IconValues.NONE, new ButtonProvider(), false) {
@Override
protected void configureState(CellContext context) {
super.configureState(context);
rendererComponent.getComponent().setVisible(true);
}
}
));
现在荧光笔可以无畏地改变基于上下文可见。一个轻微的视觉障碍:WrappingIconPanel总是为图标留下一些空间,即使没有 - 不太清楚为什么会发生这种情况,或者是否安全(在SwingX中)删除该空格(wrapppingProvider最初是为了用于JXTree,它没有默认安装,因为ComponentOrientation仍然存在问题)。
(2问题)不支持,则componentProvider被设计为返回与完全相同的特性,配置了相同的单个部件上的每个呼叫
(3中的问题)...咳嗽没有,只是来源和实例(在演示和测试包)
编辑(回答这个问题的编辑部分)
不,与当前的WrappingIconpPanel:它确实使用了Borderlayout--我们都知道:-)不尊重最大尺寸。使用BoxLayout可能会遇到一些我不完全记得的问题。尽管如此,这将是调整的地方,以便该按钮的最大值将受到尊重
嗯...不完全确定您是如何实现光标更改。假设它位于ButtonProvider中:实现isRolloverEnabled以根据其是否可见返回true/false 编辑不起作用。不知道为什么,可能是因为这是在倾倒dectection中的错误和/或WrappingProvider
处理关到周末,现在:-)
非常感谢您对您的准确和完整的答案:)请看看我的编辑,另一个问题弹出在我的脑海! – ixM 2012-02-17 16:31:17
感谢您的更新:)有一个很好的W - E! – ixM 2012-02-17 21:16:07
我有一个奇怪的错误。 Eclipse无法找到ButtonProvider类。我的类路径中有SwingX 1.6.4二进制jar。 – Marco 2013-03-19 17:41:57