I have a CardDetailsPanel
class that contains several JLabel
and JTextField
s. This class is contained in the AddCardsPanel
and initialized as follows:
cardDetailsPanel = new CardDetailsPanel(true); add(cardDetailsPanel, java.awt.BorderLayout.CENTER);
I also have a JLabel
containing instructions. I want to update this label when the CardDetailsPanel
first appears and when the focus changes to each JTextField
. I found the addFocusListener()
method that will work for a later one. However, my compenentShown()
method does not work for the first:
addComponentListener(new java.awt.event.ComponentAdapter() { public void componentShown(java.awt.event.ComponentEvent evt) { formComponentShown(evt); } });
(Well, I know this is ugly. It was created by NetBeans.)
private void formComponentShown(java.awt.event.ComponentEvent evt) { this.frame = (BaseballFrame) this.getParent().getParent().getParent().getParent().getParent().getParent(); }
(Yes, this is even more ugly. I will deal with the chained getParent()
calls later. I also want to do other things.)
So why is my listener not called? And how do I write a listener that will perform some actions when my CardDetailsPanel
appears on the screen?
source share