gpt4 book ai didi

java - 在屏幕上绘图,在shell外使用java swt?

转载 作者:行者123 更新时间:2023-12-02 05:40:35 26 4
gpt4 key购买 nike

我看到一个 Eclipse 编辑器(e4 css spy ),它在打开的外壳周围绘制了一个小框架。
它在屏幕上绘制框架,在外壳之外。
当外壳移开时,边框仍保留在屏幕上。

我应该使用什么 API 直接在屏幕上绘图,而不需要窗口?

enter image description here

最佳答案

它创建一个新的非矩形外壳:

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,并为了清晰起见重新格式化。

关于java - 在屏幕上绘图,在shell外使用java swt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24558465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com