Java: passing the value of a String to another class to use for setText on Pane -


i quite new this, not understand how classes communicate despite reading docs, think need working example drill in.

i have jlist , jeditorpane sharing jsplitpane. list functionality fine, jeditorpane in class, have obtained string need by:

public void setbookmarkpreview(listselectionevent evt) { bookmarkstring = (string)this.getselectedvalue(); //system.out.println(bookmarkstring); 

this works, have no idea how pass string "bookmarkpreview" class extends jeditorpane, can display retrieved result above on editor pane second class.

i've tried reading online can't head around context.

i created

public static string bookmarkstring; 

thinking updated based on list listener method, result in class 2 prints "null" missing here.

here second class tried call public static string

public class bookmarkpreview extends jeditorpane {  public bookmarkpreview() {  bookmarkpane test = new bookmarkpane();  this.seteditable(false); settext(bookmarkpane.bookmarkstring); system.out.println(bookmarkpane.bookmarkstring); }    } 

please, if can provide example using wording appreciated, directing me docs won't assure have have been trying ages wrap head around scratch.

*update**

ok have created getters/setters:

public void bookmarkpreview(listselectionevent evt) { bookmarkstring = (string)this.getselectedvalue(); setbookmarkstring(bookmarkstring);  }   public string getbookmarkstring() {     return bookmarkstring; }  public void setbookmarkstring(string bookmarkstring) {     this.bookmarkstring = bookmarkstring; } 

and updated class wants recieve it:

public bookmarkpreview() { bookmarkpane test = new bookmarkpane(); test.getbookmarkstring(); this.seteditable(false); settext(test.getbookmarkstring()); system.out.println(test.getbookmarkstring()); }    }    

still nothing appears in jeditorpane.

this depend on way want communication work.

to mind, editor doesn't care book mark list, list want know editor (so can set book mark).

what maintain reference editor within list component (passed in either via constructor or setter of kind) allow list, when it's changed call method of editor update bookmark position (such setbookmark).

equally, allow list request book mark editor @ it's current position, maybe newbookmark or such


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -