java - Share variable between classes - Pane Constructors -
i'm newbie in java , ask quite simple question concerns classes:
i have class needs name of pane further introduced afterwards:
private final class customdocumentfilter extends documentfilter { private final styleddocument styleddocument = pane.getstyleddocument(); // etc etc } private void cree_ihm() { container pane = getcontentpane(); ((abstractdocument) pane.getdocument()).setdocumentfilter(new customdocumentfilter()); // etc etc }
which sure doesn't work because pane defined afterwards. think problem don't understand how deal classes in functions' environment.
i appreciate help.
you can't use variable in field that, you'll need use constructor field assignment.
the
java.awt.container
class returnedgetcontentpane()
not havegetstyleddocument()
orgetdocument()
method. needjtextpane
.
also not sure why had private class.
public final class customdocumentfilter extends documentfilter { private styleddocument styleddocument; private jtextpane pane; public customdocumentfilter(jtextpane pane) { this.pane = pane; // not necessary this.styleddocument = pane.getstyleddocument(); } // override documentfilter methods here insert , remove }
i assume method in class somewhere?
private void cree_ihm() { jtextpane pane = new jtextpane(); // <-- jtextpane somewhere ((abstractdocument) pane.getdocument()).setdocumentfilter(new customdocumentfilter(pane)); }
Comments
Post a Comment