- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这个问题类似于Paint on a glass pane without repainting other components 。但我不知道如何应用那里提供的解决方案。
我的问题是我们有一个非常复杂的 RootPane,有很多组件,并且重新绘制它的成本很高。我们还有一个在 JFrame 的 GlassPane 上运行的动画。我注意到动画的每个刻度都会按照应有的方式重新绘制动画,但也会导致底层 RootPane 上的所有内容也被重新绘制。
我尝试使用各种代码覆盖 RootPane 的 Paint() 方法,但它总是会导致 RootPane 上的组件被删除并出现大量闪烁,可能是因为子组件在动画期间更新时尝试重新绘制自身:
pnlContent = new JRootPane() {
@Override
public void paint(Graphics g) {
OurGlassPaneWithAnimation glass = ...
if (glass != null && glass.animation != null && glass.animation.isAlive()) {
//Animation running, do something cool so root pane still looks good without repainting out the wazoo
} else { super.paint(g); }
}
};
也许将动画放在 GlassPane 中是个坏主意?我们考虑过将其更改为位于居中的 JPanel 中。或者有没有一种好方法可以使用 GlassPane 来实现此目的,并将对背景 RootPane 的重绘保持在最低限度?
最佳答案
@MadProgrammer 感谢您的建议,使用 repaint(rect) 而不是仅仅使用 repaint() 解决了问题。现在我们可以将动画 fps 调高到我们想要的程度,并且不会明显影响其后面的 RootPane 的加载时间。这是代码片段。
while (keepOnAnimating) {
BufferedImage bi = vFrames.elementAt(0);
if (bi != null) {
// This only repaints area of image rect
// Prevents lots of repaints from happening in rootpane behind glasspane.
int x = getWidth() / 2 - bi.getWidth() / 2;
int y = getHeight() / 2 - bi.getHeight() / 2;
jc.repaint(x, y, bi.getWidth(), bi.getHeight());
} else {
jc.repaint();
}
...
}
关于java - 防止 RootPane 重绘 GlassPane 重绘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29784969/
好吧,我浏览了多个论坛和谷歌,但找不到我的具体问题的答案。所以我有两个面板堆叠在一起,上面的一个是玻璃面板。当您在 glassPane 周围拖动鼠标时,它会在光标处绘制一条垂直的红线,这是有效的,但是
(在我的 Swing GUI 应用程序中)我想在单击 JButton 后调用的循环或方法中执行的某些工作期间显示 GlassPane。 例如:(单击按钮后执行的操作) if (item.equals(
我创建了一个 JPanel我在里面放了一个 JCheckBox和两个按钮: 选中复选框时,面板上方会显示一个透明色 (alpha = 100) 的玻璃 Pane ,并包含一个显示 String 的标签
当输入与我对用户的期望不同时,我有一个类在文本字段后面设置警告图标。对于文本字段,此类工作完美,但是当我尝试将其与文本区域一起使用时,警告图标未设置在正确的位置。 这是设置和删除警告图标的类: pub
此方法将从 JFrame 获取玻璃面板,该引用存储在 JPanel 对象中,我正在使用 JPanel 对象中的 getGraphics 获取图形引用,然后尝试为玻璃面板绘制背景图像,当我运行此代码时它
我用 java 构建了一个小型 GUI 游戏,有时我使用 glassPane 暂时阻止所有鼠标输入。我以前使用过 glassPane 没有任何问题,但这次它不会阻止鼠标输入。因此,在启用 glassP
是否可以为单个 JFrame 添加多个 GlassPane,或者我必须使用不舒服的 LayeredPane 和 不透明度 属性。 我附上了一些显示我想做什么的代码(由@camickr 提供)。 imp
在下面的应用程序中,我放置了一个按钮,单击该按钮使 GlassPane 可见,并启动一个线程来更新进度栏值。下面是代码:- import java.awt.Color; import java.awt
我正在尝试使用 GlassPane 在 Swing 应用程序中进行可视化拖放,但遇到了拖动图像滞后于鼠标指针的问题,有时甚至相当严重。我该如何解决这个问题?我的 GlassPane 代码如下。谢谢!
我一直在开发一个小型java应用程序,我想在应用程序的根 Pane 的玻璃 Pane 上添加一个等待图形,这里是类: public class WaitPanel extends JPanel { p
我在网络上发现了这个阻塞 GlassPane 类,我很想知道你们中的一些人是否发现它有任何问题。 public final class BlockingGlassPane extends JCompo
我有一个带有一些选项卡的 JTabbedPane,并且选项卡旁边有很多未使用的额外空间。所以我正在尝试使用它并在那里放置一些按钮(就像在 Eclipse 中一样)。我将按钮放在 GlassPane 上
我想使用 glassPane 函数在加载数据期间停用面板中的组件。我知道玻璃板仅适用于框架。在我的应用程序中,我无法访问该框架。我只想停用框架中的单个面板。 我尝试通过重写面板的paint或paint
我构建了一个简单的界面来填充我的整个 JFrame。我正在使用在互联网上发现的 FinalGlassPane 类的版本 here . 此玻璃 Pane 没有常规事件监听器,但它监视其基础组件的 AWT
我试图通过 JDialog 查看 GlassPane,但上面没有任何可见内容。为什么会发生这种情况?如何使 GlassPane 在 JDialog 上可见? 这就是我正在做的事情: public cl
我一直在尝试为我的游戏的游戏内 HUD 实现 GlassPane,但现在我似乎无法获得 JFrame 来设置我的 GlassPane 作为自己的我已经使用了 setGlassPane() 并且我一直在
我有一个需要几秒钟才能完成的 java 例程。我想加载一个 GlassPane(内部可能带有“prease wait”消息),以防止用户在该例程正在执行时修改 UI,并在例程完成时自动隐藏。为此,我使
我在玻璃面板上放置了一个组合框组件,供用户从项目列表中进行选择。当单击下拉列表时,虽然 JPopupMenu 隐藏在玻璃 Pane 上组件的其他部分后面,因为弹出窗口显示在 LayeredPane 上
堆栈溢出! 我正在开展一个项目,涉及制作导航系统,我们正处于开始阶段,正在绘制 map 并自行导航。我们有一个函数,您应该能够在已经绘制的当前数据之上绘制一个正方形。我想避免在每个 mouseDrag
这个问题可能只是因为我缺乏对 Java Swing 或 Graphics 的基本了解,如果是这样,我深表歉意。 我正在尝试使用 Java Swing 开发一个 GUI 应用程序,该应用程序可以由外部设
我是一名优秀的程序员,十分优秀!