This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listener to call other component's listners

 
Santhosh Raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure isn't clear to me. I agree with m korbel, post an SSCCE.
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
- 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
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Paul C.
Work out what you want, then code it afterwards.
 
Santhosh Raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2941
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please BeForthrightWhenCrossPostingToOtherSites, or better still just don't do it.
 
Santhosh Raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
Sorry for that and its been taken care.
Could you please answer my query?
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Santhosh Raj
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic