Swing - 使用UpdateUI更改面板的内容 [英] Swing - Changing the content of a panel using UpdateUI

查看:132
本文介绍了Swing - 使用UpdateUI更改面板的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览一个使用Swing的遗留应用程序,我正在努力弄清楚当用户点击按钮时屏幕如何变化。我无法弄清楚这一点的原因之一是因为这是我第一次使用Swing。我读了一本书,得到了基础知识,但仍在苦苦挣扎。

I am going through a legacy application which is using Swing and i am struggling to figure out how the screens are changing when a user clicks a button. One of the reasons i cant figure this out is because this is the first time i am using Swing. I have read a book and got the basics but still struggling.

基本上,我正在看的屏幕上有一个JSplitPane,左边有一些快捷按钮,右边有一个空窗格。当我单击按钮时,右侧窗格将根据按下的按钮填充不同的屏幕。

Basically, the screen i am looking at has a JSplitPane which has a number of shortcut buttons on the left and an empty pane on the right. When i click on the button, the right side pane is populated with a different screen depending on the button pressed.

通过代码,我希望某个地方会有一些调用setVisible()方法的东西,具体取决于按下哪个按钮。

Going through the code, i was expecting somewhere that there will be something that calls a setVisible() method depending on which button is pressed.

每个快捷按钮的actionPerformed方法如下所示:

The actionPerformed method for each of the shortcut buttons looks something like this:

void shortCutBtn_actionPerformed(ActionEvent e) {
   propertyChangeListeners.firePropertyChange("selectedShortCut", previousShortCutSel, currentShortCutSel);
   mainPanel.updateUI();
  }

我已经完成了大部分代码并得出以上结论代码是导致帧切换的原因,但我不明白这是怎么回事。

I have gone through most of the code and came to a conclusion that the above code is what is causing the frame switching but i dont understand how that is happening.

每个屏幕都由数字常量标识。在上面的代码示例中,previousShortCutSel和previousShortCutSel引用表示各个屏幕的数值。

Each screen is identified by a numeric constant. In the above code example, previousShortCutSel and previousShortCutSel refer to a numeric value that represents individual screens screen.

我试图查找updateUI()如何工作的文档,但我迷路了。以上是如何使用新屏幕更新JSplitPanel右侧面板的内容?

I have tried to look for documentation of how updateUI() works but i am lost. How does the above cause the content of the right panel of the JSplitPanel to be updated with a new screen?

推荐答案

根据ziggy的评论(很高兴帮助)

As per comments by ziggy (glad it helped)

看看似乎在代码中添加的 PropertyChangeListener 。特别是 propertyChange(PropertyChangeEvent e)方法是改变内容的代码所在的位置。

Have a look at the PropertyChangeListeners that appear to be added in the code. In particular the propertyChange(PropertyChangeEvent e) method is where the code which changes the content will be present.

+ 1到trashgod好的例子/建议一如既往

+1 to trashgod nice example/advice as always

这篇关于Swing - 使用UpdateUI更改面板的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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