How to receive events from a jcombobox in an internal Jpanel ??  
Author Message
Etantonio





PostPosted: 2006-11-15 6:51:00 Top

java-programmer, How to receive events from a jcombobox in an internal Jpanel ?? Good evening,
I've a Frame with two Jpanel, in Jpanel1 I've a Jcombobox and it's
listener while in Jpanel2 I've a JLabel where I want to write the
selected value of the Jcombobox,
Jpanel1 , Jpanel2 and the main frame are in 3 separate class and files,
this because I want to arrange a modular design.
My question is how I can receive in the main Frame the event coming
from Jcombox value changed in Jpanel1 ???

Thanks for your help

Antonio
www.etantonio.it/en

 
Knute Johnson





PostPosted: 2006-11-15 7:58:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? Etantonio wrote:
> Good evening,
> I've a Frame with two Jpanel, in Jpanel1 I've a Jcombobox and it's
> listener while in Jpanel2 I've a JLabel where I want to write the
> selected value of the Jcombobox,
> Jpanel1 , Jpanel2 and the main frame are in 3 separate class and files,
> this because I want to arrange a modular design.
> My question is how I can receive in the main Frame the event coming
> from Jcombox value changed in Jpanel1 ???
>
> Thanks for your help
>
> Antonio
> www.etantonio.it/en
>

Write an event listener in your main Frame and use that listener on your
JComboBox.

--

Knute Johnson
email s/nospam/knute/
 
Etantonio





PostPosted: 2006-11-15 15:42:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? I already have an event listener in the main frame, but I've also one
in Jpanel1 and when I change the selected value in the combobox the
scheduler go in this last one event listener, how I can dispach to the
Frame listener ???

Thanks


Antonio
www.etantonio.it/en


Knute Johnson ha scritto:

> Etantonio wrote:
> > Good evening,
> > I've a Frame with two Jpanel, in Jpanel1 I've a Jcombobox and it's
> > listener while in Jpanel2 I've a JLabel where I want to write the
> > selected value of the Jcombobox,
> > Jpanel1 , Jpanel2 and the main frame are in 3 separate class and files,
> > this because I want to arrange a modular design.
> > My question is how I can receive in the main Frame the event coming
> > from Jcombox value changed in Jpanel1 ???
> >
> > Thanks for your help
> >
> > Antonio
> > www.etantonio.it/en
> >
>
> Write an event listener in your main Frame and use that listener on your
> JComboBox.
>
> --
>
> Knute Johnson
> email s/nospam/knute/

 
 
Ian Wilson





PostPosted: 2006-11-15 22:18:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? Etantonio wrote:
> Good evening,
> I've a Frame with two Jpanel, in Jpanel1 I've a Jcombobox and it's
> listener while in Jpanel2 I've a JLabel where I want to write the
> selected value of the Jcombobox,
> Jpanel1 , Jpanel2 and the main frame are in 3 separate class and files,
> this because I want to arrange a modular design.
> My question is how I can receive in the main Frame the event coming
> from Jcombox value changed in Jpanel1 ???
>

This has been asked recently in one of the Java newsgroups - I'd use
Google to find the other answers ...

I'd pass to JPanel1 a reference to your main frame so that in Jpanel1
you can either set the JComboBox's listener to be the main frame or you
can have the actionListener invoke a method in the main frame.

You could instead define your own Listener interface and have JPanel 1
implement it, then the main frame can register itself with e.g.
JPanel1.addListener() as a listener for the events.

In JPanel2 I'd create a setXXX method for setting the JLabel value
rather than invoking JPanel2.label.setText() directly from the main frame.


 
 
Ian Wilson





PostPosted: 2006-11-16 0:09:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? Etantonio top-posted:
> I already have an event listener in the main frame, but I've also one
> in Jpanel1 and when I change the selected value in the combobox the
> scheduler go in this last one event listener, how I can dispach to the
> Frame listener ???
>

Answered in one of the other newsgroups you multi-posted to.
 
 
Etantonio





PostPosted: 2006-11-16 23:59:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? I followed your suggestion, now this is the itemStateChanged inside
Jpanel1,
to it I pass the frame in mainContainer , the result is that all its ok
but the
graphic doesn't change, any help on this ???


public void itemStateChanged(ItemEvent e) {
System.out.println("Sono nell'itemStateChanged");
JComboBox cb = (JComboBox) e.getSource();
String newSelection = (String) cb.getSelectedItem();

if (newSelection.equals("2")){

((MetronomoMain)mainContainer).setPannelloGraficaMetronomo(new
Metro2Tempi());
}else if(newSelection.equals("3")){

((MetronomoMain)mainContainer).setPannelloGraficaMetronomo(new
Metro3Tempi());


((MetronomoMain)mainContainer).getPannelloGraficaMetronomo().repaint();
}


Antonio
www.etantonio.it/en




Ian Wilson ha scritto:

> Etantonio wrote:
> > Good evening,
> > I've a Frame with two Jpanel, in Jpanel1 I've a Jcombobox and it's
> > listener while in Jpanel2 I've a JLabel where I want to write the
> > selected value of the Jcombobox,
> > Jpanel1 , Jpanel2 and the main frame are in 3 separate class and files,
> > this because I want to arrange a modular design.
> > My question is how I can receive in the main Frame the event coming
> > from Jcombox value changed in Jpanel1 ???
> >
>
> This has been asked recently in one of the Java newsgroups - I'd use
> Google to find the other answers ...
>
> I'd pass to JPanel1 a reference to your main frame so that in Jpanel1
> you can either set the JComboBox's listener to be the main frame or you
> can have the actionListener invoke a method in the main frame.
>
> You could instead define your own Listener interface and have JPanel 1
> implement it, then the main frame can register itself with e.g.
> JPanel1.addListener() as a listener for the events.
>
> In JPanel2 I'd create a setXXX method for setting the JLabel value
> rather than invoking JPanel2.label.setText() directly from the main frame.

 
 
Andrew Thompson





PostPosted: 2006-11-17 0:14:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? Etantonio wrote:

Please refrain from top-posting.

> I followed your suggestion, now this is the itemStateChanged inside
> Jpanel1,
> to it I pass the frame in mainContainer , the result is that all its ok
> but the
> graphic ..

graphic? Are you using images or icons?

>...doesn't change, any help on this ???

Perhaps you need to post a complete *short*
example (e.g. just two choices) of code that fails.
Further info. <http://www.physci.org/codes/sscce/>

Andrew T.

 
 
Etantonio





PostPosted: 2006-11-17 0:58:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? Here's the code I arranged until now

http://www.etantonio.it/temp/metronomo.zip

it is not really beauty, I'll be grateful to who want to help me to
structure it in a reasonably way,
I really don't like to have all in just one class and also I don't like
to pass object like frame like argument to a lower hierarchy object
like a Jpanel but I think I cannot obtain both the results.

many thanks for your help

Antonio
www.etantonio.it/en




Andrew Thompson ha scritto:

> Etantonio wrote:
>
> Please refrain from top-posting.
>
> > I followed your suggestion, now this is the itemStateChanged inside
> > Jpanel1,
> > to it I pass the frame in mainContainer , the result is that all its ok
> > but the
> > graphic ..
>
> graphic? Are you using images or icons?
>
> >...doesn't change, any help on this ???
>
> Perhaps you need to post a complete *short*
> example (e.g. just two choices) of code that fails.
> Further info. <http://www.physci.org/codes/sscce/>
>
> Andrew T.

 
 
Ian Wilson





PostPosted: 2006-11-17 1:52:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? Etantonio wrote:
> Here's the code I arranged until now
>
> http://www.etantonio.it/temp/metronomo.zip

I find that making helpers do unnecessary work makes for fewer helpers.


> Andrew Thompson ha scritto:
>> Please refrain from top-posting.

You seem to be ignoring good advice.


>> Perhaps you need to post a complete *short* example (e.g. just two
>> choices) of code that fails. Further info.
>> <http://www.physci.org/codes/sscce/>

A reference to a zip file suggests to me that the code isn't *short*.

Can you not strip that down to a 30 line example you can post here?
 
 
Etantonio





PostPosted: 2006-11-17 3:51:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? Maybe I'm to wrong ...
thanks anyway



Ian Wilson ha scritto:

> Etantonio wrote:
> > Here's the code I arranged until now
> >
> > http://www.etantonio.it/temp/metronomo.zip
>
> I find that making helpers do unnecessary work makes for fewer helpers.
>
>
> > Andrew Thompson ha scritto:
> >> Please refrain from top-posting.
>
> You seem to be ignoring good advice.
>
>
> >> Perhaps you need to post a complete *short* example (e.g. just two
> >> choices) of code that fails. Further info.
> >> <http://www.physci.org/codes/sscce/>
>
> A reference to a zip file suggests to me that the code isn't *short*.
>
> Can you not strip that down to a 30 line example you can post here?

 
 
Andrew Thompson





PostPosted: 2006-11-17 11:34:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? Ian Wilson wrote:
> Etantonio wrote:
> > Here's the code I arranged until now
...
> Can you not strip that down to a 30 line example you can post here?

I'll 'second' that. Anything short enough for an SSCCE,
needs no zip file.

Andrew T.

 
 
steve





PostPosted: 2006-11-17 20:21:00 Top

java-programmer >> How to receive events from a jcombobox in an internal Jpanel ?? On Wed, 15 Nov 2006 06:50:30 +0800, Etantonio wrote
(in article <email***@***.com>):

> Good evening,
> I've a Frame with two Jpanel, in Jpanel1 I've a Jcombobox and it's
> listener while in Jpanel2 I've a JLabel where I want to write the
> selected value of the Jcombobox,
> Jpanel1 , Jpanel2 and the main frame are in 3 separate class and files,
> this because I want to arrange a modular design.
> My question is how I can receive in the main Frame the event coming
> from Jcombox value changed in Jpanel1 ???
>
> Thanks for your help
>
> Antonio
> www.etantonio.it/en
>

arrange a listener.


some place in your jpanel( E.G GetReportIndex) have a section of code like
this

firePropertyChange( "REPORT", true,false);



that fires whenever the list changes.

in your main frame register a listener

GetReportIndex.addPropertyChangeListener("REPORT",new
PropertyChangeListener()
{
.................

}
}
});


basically in your frame you have acess to the names of both of your panels.
in my case one of my panels is called "GetReportIndex"
this is a text box that takes user input.

i ensure that when the user has done with their input i fire a property
change
firePropertyChange( "REPORT", true,false);

this is picked up in the main frame because i have a listener registered
looking for property changes in "GetReportIndex"



make sure of the following:

1. you de-register the listener when finished or you will get a memory leak.
2. you have some sanity code that only fires a change when something has
actually changed., many re-draw operations , cause a list to re-fire its
properties.



Steve