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.

  1. you can't use variable in field that, you'll need use constructor field assignment.

  2. the java.awt.container class returned getcontentpane() not have getstyleddocument() or getdocument() method. need jtextpane.

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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -