Accessing the menu from a ChartPanel?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Tom Carden

Accessing the menu from a ChartPanel?

Post by Tom Carden » Tue Oct 01, 2002 5:07 pm

At the moment I'm using a ChartPanel in a javax.swing.JInternalFrame, and it's working brilliantly. However, I'd like to change the menu from being a JPopupMenu to a JMenuBar on the JInternalFrame. I've pretty much accomplished this like so:

-----------------------------------
ChartPanel chartPanel = new ChartPanel(getMyChart());

JInternalFrame chartFrame = new JInternalFrame("Chart Test");
chartFrame.getContentPane().add(chartPanel);

JMenu chartMenu = new JMenu("Chart Options");
MenuElement[] menuElements = chartPanel.getPopupMenu().getSubElements();
for (int i = 0; i < menuElements.length; i++) {
chartMenu.add((JMenuItem)menuElements);
}
JMenuBar chartMenuBar = new JMenuBar();
chartMenuBar.add(chartMenu);
chartFrame.setJMenuBar(chartMenuBar);

-----------------------------

The menubar of the frame now contains the chart controls as required. The problem is that a small, empty, JPopupMenu remains active upon right click. Is there a way I can get rid of this? Can access to a control menu (built on demand?) be given so that this works even if the menu is turned off using the constructor?

Thanks for reading,

Tom.

David Gilbert

Re: Accessing the menu from a ChartPanel?

Post by David Gilbert » Tue Oct 01, 2002 11:22 pm

You should be able to set the popup menu on the ChartPanel to null, and then nothing will be displayed.

Regards,

DG

Tom Carden

Re: Accessing the menu from a ChartPanel?

Post by Tom Carden » Wed Oct 02, 2002 9:38 am

Oh yeah, I didn't think of that (obviously!).

Brilliant software, brilliant support. Thank you.

Locked