Click to See Complete Forum and Search --> : event handling


pradeep_p43
May 28th, 2002, 02:35 AM
There are several JLabels in a JPanel having GridBagLayout.
A new JLabel is added to the JPanel, when the existing JLabel in the left JPanel is dragged and dropped in the right Jpanel.And accordingly i am increasing the i value for the JLabel, which are created as an array of JLabels.Now after getting (say 12) number of JLabels in the right JPanel, i just wanted to change the layout of the present JLabels.
My problem is... how can i figure out which particular JLabel is the source of an event ? i.e. how can i get the value of i( i.e. the index of JLabel arrays), on which the particular event has been fired...

please make it fast.....

as i am stuck with this...

N.B. i know that i have to use e.getSource()...but my problem is to get the particular JLabel( i.e. the value of i)...
it will be nice if u can write with code...

pradeep

Norm
May 28th, 2002, 09:48 AM
If you have a reference to the object that caused the event, then to get some data from that object you will have to call a method on that object to get that data. Read the doc for the type of object(JLabel) and see what method will return the data that you want.

Tip: You will need to cast the Object to the correct type to be able to use its methods.

Or post your code if you don't understand how do to that and someone might be able to help.

pradeep_p43
May 29th, 2002, 07:43 AM
even i was thinking the same...i.e. to port the code...but before that let me explain what basically i want to do...

i want to have an IDE sortof thing (like VB) in Swing, in whcih from left pane, i should be able to drag and drop controls in the right panel and in the required position and need less to say, each time i drag and drop the same control, it should give me a new control in the right side pane. And i should be able to drag from one place to other any of the controls present in the right pane.....
hope i have made it clear this time...
i think someone might have already developed something like it...if he/she can throw some light on this(might be with code)..it will be a great help...
waiting for a reply..

any information is valuable......

hope to listen early...

pradeep