在组件边界外绘图 [英] Drawing outside a component's bounds

查看:178
本文介绍了在组件边界外绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个组件(扩展JComponent),它将在其顶部绘制一些装饰,部分在其边界之外。

I'm making a component (extending JComponent) which will have some decoration drawn over the top of it and partly outside its bounds.

我想知道如果有一种使用自包含代码在组件外部绘制的方法(例如,我不想在父容器中进行任何绘制)。

I would like to know if there's a way of drawing outside the component using self-contained code (I don't want to have to do any drawing in the parent container, for example).

推荐答案

AFAIK,没有简单的解决方案。实现此目的的一种方法是绘制容器的 GlassPane ,如图所示此处。恕我直言,我只想修改组件的 Graphics 对象来改变明显边界,这将使你能够在组件本身上绘制超出范围的东西。

AFAIK, there is no easy solution. One way to achieve this is to draw on the container's GlassPane, as shown here. IMHO, I would just modify the Graphics object of the component to change the "apparent" bounds, which will enable you to draw stuff that's "outside the bounds" on the component itself.

这篇关于在组件边界外绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆