使用java swt在shell外面绘制外壳?

时间:2014-07-03 15:59:47

标签: java drawing swt

我看到了一个eclipse编辑器(e4 css spy),它在开放的炮弹周围绘制一个小框架。
它在屏幕上绘制框架,远离外壳。
当贝壳移开时,边框停留在屏幕上。

我应该使用什么API直接在屏幕上绘制,没有窗口?

enter image description here

1 个答案:

答案 0 :(得分:2)

它创建一个新的非矩形shell:

Shell selectedShell = ... get the shell to highlight

Rectangle bounds = .. get bounds relative to absolute display

// create the highlight; want it to appear on top

Shell highlight = new Shell(selectedShell, SWT.NO_TRIM | SWT.MODELESS | SWT.NO_FOCUS | SWT.ON_TOP);

highlight.setBackground(display.getSystemColor(SWT.COLOR_RED));

Region highlightRegion = new Region();
highlightRegion.add(0, 0, 1, bounds.height + 2);
highlightRegion.add(0, 0, bounds.width + 2, 1);
highlightRegion.add(bounds.width + 1, 0, 1, bounds.height + 2);
highlightRegion.add(0, bounds.height + 1, bounds.width + 2, 1);

highlight.setRegion(highlightRegion);

highlight.setBounds(bounds.x - 1, bounds.y - 1, bounds.width + 2, bounds.height + 2);

highlight.setEnabled(false);

highlight.setVisible(true); // not open(): setVisible() prevents taking focus

取自org.eclipse.e4.tools.css.spy.CssSpyDialog并重新格式化以便清晰。