You are not logged in.

#1 2010-11-21 20:25:22

Thor@Flanders
Member
Registered: 2010-08-27
Posts: 266

How do I make a JPanel fire an(y) event?

Hi,

As the title implies, I need a JPanel to fire an event, any event will do, it is embedded into an interface and needs to signal the parent component that it is ready with data. The JPanel is to collect data and is to have a JButton on it, firing an event that the listener can capture and react to by extracting the data from the JPanel.

JInternalFrames have this:

private void doFireAnEvent()
{
// fire an event the listener can hear
this.fireInternalFrameEvent(InternalFrameEvent .INTERNAL_FRAME_CLOSING);
}

The "parent" listens with a frame listener

myThing.addInternalFrameListener(new InternalFrameListener()
{
public void internalFrameClosing(InternalFrameEvent e) 
{
// capture the fired event here

}    
public void internalFrameClosed(InternalFrameEvent e) 
{
}
public void internalFrameOpened(InternalFrameEvent e) 
{
}
public void internalFrameIconified(InternalFrameEvent e) 
{
}
public void internalFrameDeiconified(InternalFrameEvent e) 
{
}
public void internalFrameActivated(InternalFrameEvent e) 
{
}
public void internalFrameDeactivated(InternalFrameEvent e) 
{
}
});

Do JPanels have something similar? I've been all over the Net and came out blank...
By the way, I cannot use a JInternalFrame, it has to be a JPanel...
I hope some "wise ones" can help me see the lite... smile

Thanks

Thor

Last edited by Thor@Flanders (2010-11-22 08:45:50)

Offline

#2 2010-11-21 20:49:33

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,580

Re: How do I make a JPanel fire an(y) event?

You could use the standard Beans support.  A JPanel is a JComponent, and the following method is available:

public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)

Your "parent" could just add a PropertyChangeListener and listen for PropertyChangeEvents with whatever propertyName you choose to fire

Offline

#3 2010-11-21 21:01:01

Thor@Flanders
Member
Registered: 2010-08-27
Posts: 266

Re: How do I make a JPanel fire an(y) event?

Hi Skunktrader!

Just tried it...with succes!

Man, I so owe you a beer! smile

Thanks!

Thor

Offline

Board footer

Powered by FluxBB