提问人:Satya 提问时间:10/12/2023 最后编辑:Satya 更新时间:10/12/2023 访问量:34
将鼠标悬停在树的整行上
Hover color for entire row of the tree
问:
我有一个 swt 树,我为其添加了 SWT。EraseItem 侦听器为了获取选择,将鼠标悬停在树项的颜色上。选择,悬停颜色显示正确,但该颜色仅应用于文本。我希望它应用于整行。
截图供您参考:
tree.addListener(SWT.EraseItem, new Listener() {
@Override
public void handleEvent(Event event) {
if ((event.detail & SWT.SELECTED) != 0 && (event.detail & SWT.MouseHover) != 0) {
int width = getBounds().width;
GC gc = event.gc;
gc.setForeground(new Color(Display.getCurrent(), 0, 0, 0));
gc.setBackground(new Color(Display.getCurrent(), 213, 215, 219));
gc.fillRectangle(0, event.y, width, event.height);
event.detail &= ~SWT.MouseHover;
event.detail &= ~SWT.SELECTED;
}
if ((event.detail & SWT.SELECTED) != 0 && !tree.isFocusControl()) {
int width = tree.getClientArea().width;
GC gc = event.gc;
gc.setForeground(new Color(Display.getCurrent(), 0, 0, 0));
gc.setBackground(new Color(Display.getCurrent(), 230, 232, 235));
gc.fillRectangle(0, event.y, width, event.height);
event.detail &= ~SWT.SELECTED;
}
if ((event.detail & SWT.MouseHover) != 0) {
int width = tree.getClientArea().width;
GC gc = event.gc;
gc.setForeground(new Color(Display.getCurrent(), 0, 0, 0));
gc.setBackground(new Color(Display.getCurrent(), 213, 215, 219));
gc.fillRectangle(0, event.y, width, event.height);
event.detail &= ~SWT.MouseHover;
}
if ((event.detail & SWT.SELECTED) != 0) {
int width = tree.getClientArea().width;
GC gc = event.gc;
gc.setForeground(new Color(Display.getCurrent(), 0, 0, 0));
gc.setBackground(new Color(Display.getCurrent(), 192, 235, 237));
gc.fillRectangle(0, event.y, width, event.height);
event.detail &= ~SWT.SELECTED;
}
Color previousForegroundColor = event.gc.getForeground();
event.gc.setForeground(previousForegroundColor);
}
});
答: 暂无答案
评论
getBounds()
SWT.MouseHover
SWT.HOT