| | |
Set text in JTextPane from another class
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 10
Reputation:
Solved Threads: 0
Im hoping this is just simple, but I have a main class for my GUI and I do some printing in another class called board, which gets its information from my peg class, which gets its information from my linked list.
Is there and easy way to print my pegs out onto my JTextPane because
This stuff works fine in my main class like this, where display is just what ive called my instance of the JTextPane
MAIN CLASS
This is where I start having trouble
BOARDCLASS
PEG CLASS
LLIST CLASS
LLNODE CLASS
Is there and easy way to print my pegs out onto my JTextPane because
System.out.print just prints out to the console. I'll show my functions here just in case its a little more complicated like having to change my void functions to string to return a value. If that is the case could some please let me know how to do that because ive tried before and couldnt do it.This stuff works fine in my main class like this, where display is just what ive called my instance of the JTextPane
MAIN CLASS
java Syntax (Toggle Plain Text)
display.setText("\n\n*** Bad Input, please try again! \n");
This is where I start having trouble
BOARDCLASS
java Syntax (Toggle Plain Text)
public void printBoard(){ System.out.print("\n\n\n\n\n\n\n\n|"); peg1.print(); System.out.print("|"); peg2.print(); System.out.print("|"); peg3.print(); System.out.print("\n\n\n\n\n\n\n"); if(peg3.topNum() == 1 && peg2.topNum() == peg1.topNum()){ gameFinish = true; } //do some debugging System.out.println(peg1.topNum() + "" + peg2.topNum() + "" + peg3.topNum()); }
PEG CLASS
java Syntax (Toggle Plain Text)
public void print() { printList(); }
LLIST CLASS
java Syntax (Toggle Plain Text)
public void printNode(llnode node) { if (node != null) { printNode(node.nextNode()); System.out.print(node.dataVal() + " "); } }
LLNODE CLASS
java Syntax (Toggle Plain Text)
public int dataVal() { return data; }
Change your print methods to return the Strings you want, rather than actually sending output to System.out. Your GUI class can then put those strings wherever it wants to. If fact you could just override toString() to return the string representation of each of those objects and do away with print() methods altogether.
An alternative is to pass a reference to a text component to each print method and let each of the objects "print" to that instead of the console, but it does limit your flexibility a bit (i.e. you can only print to a JTextComponent or whatever you decide to pass as a parameter). Overriding toString() lets you get a custom string representation for any of the objects and use it as you please.
An alternative is to pass a reference to a text component to each print method and let each of the objects "print" to that instead of the console, but it does limit your flexibility a bit (i.e. you can only print to a JTextComponent or whatever you decide to pass as a parameter). Overriding toString() lets you get a custom string representation for any of the objects and use it as you please.
![]() |
Similar Threads
- JTextPane TabStop problem (Java)
- JTable Cell Renderers (Java)
- JTextPane (Java)
- Printing Embedded JComponents (Java)
- Hyperlinks (Java)
Other Threads in the Java Forum
- Previous Thread: adding new listeningPoint
- Next Thread: APPLETS and server
Views: 1932 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor database draw eclipse error event eventlistener exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me jar java javafx javamicroeditionuseofmotionsensor javaprojects jmf jni jpanel jtree julia link linux list loop machine map method methods mobile netbeans newbie nls number object oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms socket sort sortedmaps sql string swing test textfield threads time transfer tree unlimited webservices windows






