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

查看:179
本文介绍了如何在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组件有重绘() ,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天全站免登陆