如何在 Java 中刷新 GUI? [英] How do I refresh a GUI in Java?

查看:125
本文介绍了如何在 Java 中刷新 GUI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与 Java 相关的一般性问题.

I have a general question that is Java related.

我正在编写一个具有 GUI 菜单的应用程序.我正在尝试根据单选按钮的选择更改 GUI 菜单的一部分.

I am writing an application that has a GUI menu. I am trying to change one part of the GUI menu based on the selection of a Radio button.

我需要:

  1. 重绘整个窗口或仅更新该部分:

  1. Redraw the whole window or just update that part with:

setVisible(true)?

  • 如果我只使用上面#1 中的语句.. GUI 很好——直到我将鼠标移到它上面,然后我看到上一个按钮选择.我做错了什么?

  • If I just use the statement from #1 above .. the GUI is fine -- until I move the mouse over it and then I see the previous button choice. What am I doing wrong?

    推荐答案

    Swing 组件具有 repaint()、revalidate() 和 doLayout() 方法.其中之一应该能够重绘您想要的任何部分.但是,doLayout 不是您应该负责的事情,这是布局引擎的责任.

    Swing components have a repaint(), revalidate(), and doLayout() method. One of those should probably be able to redraw whichever pieces you want. However, doLayout is not something that you should be taking responsibility for, that's the layout engines responsibility.

    您可能还想查看这篇文章,第一个回复有很好的解释,并链接到更详细的文章.

    You may also want to check out this post, the first response has a pretty good explanation, and links to an article with more detail.

    就您问题的第二部分而言,我不确定,但我们可能需要查看一些代码才能获得一个想法.替换区域"是否真的从视图中移除了?

    In terms of the second part of your question, I'm not sure, but we may need to see some code to get an idea. Is the 'replaced area' actually being removed from the view?

    这篇关于如何在 Java 中刷新 GUI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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