I can get a ChartEntity from the ChartMouseListener.chartMouseClicked but it only works on the left mouse click.
In testing, I can catch both mouse buttons (left and right) with a MouseListener, but not sure how the the a ChartEntity with the information
available here.
Any pointers would appreciated.
David
ChartEntity on Right Mouse Release (Button 3)
Re: ChartEntity on Right Mouse Release (Button 3)
If you look at the source code you can that JFreechart assigned the right click to the PopUpMenu :
I'm not sure what you want to do ^^
Here you can find the full code :
http://www.jfree.org/jfreechart/api/gjd ... ource.html
Code: Select all
1585: else if (e.isPopupTrigger()) {
1586: if (this.popup != null) {
1587: displayPopupMenu(e.getX(), e.getY());
1588: }
1589: }
Here you can find the full code :
http://www.jfree.org/jfreechart/api/gjd ... ource.html
Re: ChartEntity on Right Mouse Release (Button 3)
Yes, I know. I'm trying get a ChartEntity for a popup menu service routine.
The strategy was to create a ChartMouseListener to setup the ChartEntity and then run the
other ChartMouseListeners, which I thought would do the popup.
You have pointed me to the root of the problem. When there is popup configured,
The mouseRelease event (on Windows) overrides the mouseClicked event and does the popup.
In this case we NEVER get a mouseClicked event! I'm surprised by this and unless there is
an overriding reason, consider it an oversight.
The mouseClicked event processes all the ChartMouseListeners. Since the mouseRelease event
processes a popup menu and seems to consume or prevent the mouseClicked event, my original
strategy is a no go. Even if we got a mousClicked event, it would be after the popup.
I would think a better implementation would be to process the popup in the mouseRelease event,
after all the ChartMouseListeners were called.
It looks like I might have to extend the ChartPanel class by overriding the mouseRelease event to get a ChartEntity for my popup routine.
If there is a more elegant solution, I'd appreciate hearing it.
Regards,
David
The strategy was to create a ChartMouseListener to setup the ChartEntity and then run the
other ChartMouseListeners, which I thought would do the popup.
You have pointed me to the root of the problem. When there is popup configured,
The mouseRelease event (on Windows) overrides the mouseClicked event and does the popup.
In this case we NEVER get a mouseClicked event! I'm surprised by this and unless there is
an overriding reason, consider it an oversight.
The mouseClicked event processes all the ChartMouseListeners. Since the mouseRelease event
processes a popup menu and seems to consume or prevent the mouseClicked event, my original
strategy is a no go. Even if we got a mousClicked event, it would be after the popup.
I would think a better implementation would be to process the popup in the mouseRelease event,
after all the ChartMouseListeners were called.
It looks like I might have to extend the ChartPanel class by overriding the mouseRelease event to get a ChartEntity for my popup routine.
If there is a more elegant solution, I'd appreciate hearing it.
Regards,
David
Last edited by dbritton on Fri May 19, 2017 2:50 pm, edited 1 time in total.
Re: ChartEntity on Right Mouse Release (Button 3)
Well, you can also add elements to the existent Popup by taking the JMenu and then create your popup :
EDIT:
You can do your own by doing something like this :
And then in the ActionPerformed you do what you want
Code: Select all
String[] list_popup_menu = {"item1","item2","item3","item4","item5"};
JMenu popMenu = yourChartPanel.getPopupMenu();
popMenu.addSeparator();
JMenuItem popupItem;
for(String jItemName : list_popup_menu){
popupItem = new JMenuItem(jItemName);
popupItem.addActionListener(this);
popMenu.add(popupItem);
}
You can do your own by doing something like this :
Code: Select all
private void doPop(MouseEvent e){
popMenu.show(e.getComponent(), e.getX(), e.getY());
}
addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent me) {
if (me.isPopupTrigger())
doPop(me);
}
});
Re: ChartEntity on Right Mouse Release (Button 3)
I'm kinda of doing that already, but I don't know how to get a ChartEntity in the doPop(MouseEvent e)
method. As far as I know, I'd need access to ChartPanel's info object to get the EntityCollection.
Thus, the need to override ChartPanel.
method. As far as I know, I'd need access to ChartPanel's info object to get the EntityCollection.
Thus, the need to override ChartPanel.
Re: ChartEntity on Right Mouse Release (Button 3) - My Solut
Here's my solution. I created a new MouseAdaptor that will process a mouseClicked event
prior to doing a popup.
prior to doing a popup.
Code: Select all
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
if (me.isPopupTrigger())
chartPanel.mouseClicked(me);
}
});