Swing - changing panel content using UpdateUI

I am reviewing a legacy application using Swing and I am struggling to understand how the screen changes when the user clicks a button. One of the reasons why I cannot figure it out is because this is the first time I have used Swing. I read the book and got the basics but am still struggling.

Basically, the screen I'm looking at has a JSplitPane that has a few shortcut buttons on the left and an empty pane on the right. When I click on the button, the right sidebar fills with a different screen depending on the button I pressed.

Looking through the code, I expected there to be something that calls the setVisible () method depending on which button is clicked.

The actionPerformed method for each keyboard shortcut looks something like this:

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

      

I went through most of the code and came to the conclusion that the above code is what is causing the frame switching, but I do not understand how this happens.

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

I tried to find documentation on how updateUI () works, but I am lost. How does the above cause the content of the right pane of the JSplitPanel to be updated with the new screen?

+1


source to share


2 answers


According to ziggy's comments (glad it helped)

Take a look at PropertyChangeListener

which appears to be added to the code. In particular, a method propertyChange(PropertyChangeEvent e)

is code that modifies the content.



+1 to trashgod good example / advice as always

+3


source


It is a misnomer updateUI()

that "resets the UI property to the value from the current appearance". Since the example itself may be unreliable, consider exploring another. GoogleOlympiad

for example sets the label icon using a (cached) image.

ImageIcon image = getImage(index);
imageLabel.setIcon(image);

      



image
(source: drjohnbmatthews at sites.google.com )

+9


source







All Articles