JFreeChart for FX - ChartViewer - getting the focus

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
DullingWine
Posts: 7
Joined: Fri Jun 27, 2014 2:01 am
antibot: No, of course not.

JFreeChart for FX - ChartViewer - getting the focus

Post by DullingWine » Sat Feb 28, 2015 12:05 am

Hi

I'm using the javafx flavour of JFreeChart. The chart is embedded inside a split pane and is working well. I should say that i'm running it under the so far unreleased - Java 8u40. As has been noted previously there are some serious issues with the current java 8 (u25?) which render JFreecharts impossible to work with (resize etc) when embedded in JavaFX panes. u40 fixes this.

I wanted to add some keyboard shortcuts to my chart, including scrolling. Easy to add with keypressed listeners.

That was easy enough, but what was somewhat unexpected was the difficulty in giving the focus to the ChartViewer. I cannot simply click on the chart and then scroll away. I had to tab around the dialogs until the chart component had the focus.

I fixed by adding registering a doing chartViewer.setOnMouseClicked(e->{ chartViewer.requestFocus() }) ...but seems like this should be out of the box? No? Or am i missing something?

Thanks!

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: JFreeChart for FX - ChartViewer - getting the focus

Post by david.gilbert » Tue Mar 03, 2015 10:42 pm

I'll have to think about this. I think the chart viewer probably shouldn't get the focus by default, but it should definitely be something that you can set with a flag. I'm still learning JavaFX, but in my day job I am working on a big JavaFX application so I am getting better at it. :P
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

DullingWine
Posts: 7
Joined: Fri Jun 27, 2014 2:01 am
antibot: No, of course not.

Re: JFreeChart for FX - ChartViewer - getting the focus

Post by DullingWine » Tue Mar 03, 2015 11:53 pm

Thanks for the response David!

Seems to me that conventional behaviour for a component is when you click on it receive the focus..., so personally i think this should be the default - then its easy to add keyboard shortcuts etc. You could have a call to turn it remove it of course. You could also wrap this behaviour up by adding a keyboard listener from the ChartViewer API which internally added a mouse event to capture the focus - bottom line you need to have the focus to get the keyboard event.

I must admit the only thing that gives me some pause for thought right now is the division of labour between the ChartViewer and the underlying JFreeChart. To scroll the chart you need to be calling panDomainAxes on the plot. To do that however, you need to provide the plot info, derived from the rendering info...which you get from the ChartViewer. So in other words, to scroll via keyboard, i need to be passing in information from the outer component to the inner component. Seems a bit awkward..but could also be entirely due to my lack of knowledge about JFreeChart!

Locked