wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Listener to call other component's listners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Listener to call other component Watch "Listener to call other component New topic
Author

Listener to call other component's listners

Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
Hi,
I have a parent button and child button which is been added on the parent button.
I have a separate button listener for the parent button.
But I should write a listener to the child button which should perform the same action like the parent button.
Of course, I can add the same listener even to the child button.
But, the problem is, I wont get the pressed effect on the parent button when I press the child button.
So, is there any mechanism for achieving the desired result?
Your inputs would be appreciated.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 154
I have a parent button and child button which is been added on the parent button.

this doesnot make me any sence, for better help sooner post an SSCCE, short , runnable, compilable about parent v.s. child

Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
Hi Korbel,
The code looks like this.



Now I have a sepaarte action/mouse listener for parent button.
My requirement is when I perform any action on child button, the parent button's listeners should also be activated.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38003
    
  22
What a strange layout. Why on earth do you want buttons on top of each other? If you want one button to respond to two listeners, you can add two listeners to it.
Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
Hi Ritchie,
Let me be more specific here.
I have a combobox for which I have modified its editor component which will return a button.
Thus, the editor component of the combobox is now a button component.
As I have done this, the click on the editor doesnt show the list popup which should show the combobox list.
Only the arrow button is responding to the listeners.
My requirement is to display the combobox popup list when I click the modified editor component.

Another requirement is I should have a close button on the combobox so that when it is pressed, the currently selected item from combobox list should be deleted.
The deletion mechanism is easy, but getting the pressed effect on the combobox when the close button is pressed is not happening.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

This sounds to me very much as if you have some problem which you haven't told us about, and you've devised some kind of solution which doesn't work, and now you're asking us to help fix your non-working solution.

Often when this happens, it's because the proposed solution was the wrong thing to do. So why don't you start at the beginning, with the original problem? Was that the original problem which you just described in your last post, or did you do that because it was the solution to some other requirement which you haven't told us about?
Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
Its a composition of both the requirements.
1. Modified combobox editor to a Jbutton in which the combobox popup list doesnt appear when the editor component is pressed
2. A button on this editor component.

Thus, the clear picture is like this.
- Original editor component of combobox is JTextField which has been modified to JButton.
- I should add one more JButton (close button) on the modified editor (JButton)
- Once this close button is pressed, the pressed effect should come even on the editor button.

Hope it is clear now..
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Sure isn't clear to me. I agree with m korbel, post an SSCCE.
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 154
- JButton can be used as container, but only Top-Level Containers and JPanel has implemented LayoutManager, have to decide and to use proper one

- (required deepest knowledge) is possible with ButtonModel / SwingUtilities (deepestComp...???) and remove / add JButtons properties on fly, maybe nothing complicated

- (simple way) get arrays of Gradient and Borders (two - three Borders) from UIManager(button get something) or from JButton directly and put this arrays of colors to the concrete JPanel,

- (simple way) then add MouseListener a MouseMotionListener to the JPanel by simulating Border on mouseEntered/Exited, click consume() mouseListener

- (simple way) then there are two Object that looks like as JButton in the JButton

- (simple way) add KeyBindings for listening from keyboard (override ENTER key for JPanel)

- crossposted on another Java forum (without any reply, just my comments here)

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38003
    
  22
Agree with Paul C.
Work out what you want, then code it afterwards.
Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
Hi All,
Thanks for the suggestion.
I would go with that suggestion of Gradients and borders on a button.
But about my other query where in the modified combobox editor which is JButtton is not responding to display the combobox popup list when clicked.
Please let me know your valuable inputs.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2172
    
  47
Please BeForthrightWhenCrossPostingToOtherSites, or better still just don't do it.
Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
Hi Tony,
Sorry for that and its been taken care.
Could you please answer my query?
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

Santhosh Raj wrote: Hope it is clear now

No, it is not.

like Paul has asked, can you describe the actual problem? I mean describe what is expected. You have again described about the combobox, but, we are asking about the problem.
If you describe the problem, we may actually find that, you don't need a combobox to solve that and may provide a better solution.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
I have a combobox for which I have modified its editor component which will return a button.
Thus, the editor component of the combobox is now a button component.
As I have done this, the click on the editor doesnt show the list popup which should show the combobox list.
Only the arrow button of the combobox is responding to the listeners.
My requirement is to display the combobox popup list when I click the modified editor component.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

You are just repeating yourself. I don't think that leads us to anywhere.

Either you post code (SSCCE) or explain the problem, without which we can't help much.
Santhosh Raj
Greenhorn

Joined: Mar 08, 2012
Posts: 25
Hi Ranganathan,
I guess you need some insight on ComboBoxEditor here.
I am modifying the combobox editor as below.



I will be calling the above constructor to get the modified combobox editor as shown below.
Thus, the editor component of the combobox will be Button.



As I am overriding the editor compoment, I am not able to get the pressed effect, i.e, the combobox pop up list is not displayed when the editor is clicked.
Only the combox arrow button is displaying the combobox pop up list.
I want to have the original combobox effect where the popup list is shown even when the editor is clicked.

Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

This is not a SSCCE. Please click on the link to understand what it is.
We need a short runnable program which demonstrates the problem. We will then copy the code and try and reproduce the problem on our machines.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Listener to call other component's listners
 
Similar Threads
Synchronizing session between two web application
forwarding parent window
parent window refresh
error in passing values from child window to parent window
popup close event