Acoped Acoped - 1 year ago 63
Java Question

Java: Extending a class and adding a no-arg constructor (for wrapper)

I need to extend a class ChartViewer, which does not have a no-arg constructor, with a class ChartViewerWrapper to add a no-arg constructor.

How would I go about doing this?

Extra information (not that relevant)

The reason I need to do this is as a workaround as per below, the quote is taken from a forum regarding JavaFX 8 and JFreeChart. I want to use ChartViewer in FXML:

Currently the ChartViewer node cannot be used in FXML. I think the
only reason is because it does not have a constructor without
arguments (when I extended the ChartViewer class and added a simple
constructor without arguments, I could add my wrapper class into FXML
and it works).

(I could just add a no-arg constructor directly in ChartViewer, but it is an External Library and for various good reasons I decided I don't want to do this.)

Answer Source

provide a no-arg constructor in ChartViewerWrapper and on its first line call

super (arg1, arg2);

assuming that ChartViewer has two parameters

  • sorry I d not know what ChartViewer's real constructor looks like
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download