gpt4 book ai didi

java - 在 Swing 组件的顶部绘画?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:04:19 25 4
gpt4 key购买 nike

我将一个 JPanel 添加到一个 JViewport,并且该面板还添加了其他几个面板。我正在尝试实现一种拖动选择,您可以通过拖动鼠标来选择多个组件。我面临的唯一问题是选择矩形被绘制在添加到主 JPanel 的组件后面。我怎样才能在它们上面作画?

我的结构如下:
JFrame -> ContentPane -> JLayeredPane -> JScrollPane -> JPanel -> JPanel [].

大学作业设计稿:
如您所见,矩形位于其他面板的后面。

Design draft for college assignment.

最佳答案

This is what I'm already doing (on a much simpler level obviously), and Swing paints the rectangle underneath the components added to it.

在这种情况下,您应该覆盖面板的 paint() 方法而不是 paintComponent() 方法。然后自定义绘制将在所有子组件绘制完成后完成。

关于java - 在 Swing 组件的顶部绘画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8776540/

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