This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Pages: 1 - Last Post: 28-Jul-2015 10:54 Last Post By: JelleWiersma Threads: [ Previous | Next ]
JelleWiersma

Posts: 4
Registered: 31-May-2006
data from disk to JTextArea problem
Posted: 27-Jul-2015 21:35
 
  Click to reply to this thread Reply
Can someone help me
I try to get info from a diskfile into a jtextfield

the reading from disk is ok

but putting the information in the textfield fails every time.

here is what i have

JTextArea righttextAreaTemplate = new JSmartTextArea(8, 20);
=============================
private loadrightsitetext() {
fc.setFileFilter(txtFilter);
int retVal = fc.showOpenDialog(this);
if (retVal == JFileChooser.APPROVE_OPTION) {
String fn = fc.getSelectedFile().toString();
if ( !fn.trim().equals("") ) {
File src = new File(fn);
String inpline;
if (!src.exists())
return false;

StringBuilder sb = new StringBuilder();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(src), "UTF8"));
while ((inpline = in.readLine()) != null) {
inpline= inpline.trim();
sb.append(inpline);
sb.append(System.lineSeparator());
}
in.close();

righttextAreaTemplate.setText(sb); <============= this goes wrong
//righttextAreaTemplate = sb;
//System.out.println(sb) ;

}
catch (IOException e) {
fileError(src, e);
return false;
}
catch (UnsupportedEncodingException e) {
log("Encoding error", e);
}

return true;
}}}
=============================================

Exception in thread "AWT-EventQueue-0" java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy10.actionPerformed(Unknown Source)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: bsh.EvalError: Error in method invocation: Method setText( java.lang.StringBuilder ) not found in class'se.datadosen.component.JSmartTextArea' : at Line: 76 : in file: inline evaluation of: ``import se.datadosen.jalbum.; //import se.datadosen.util.; import se.datadosen. . . . '' : righttextAreaTemplate .setText ( sb )

JeffTucker

Posts: 6,962
Registered: 31-Jan-2006
Re: data from disk to JTextArea problem
Posted: 27-Jul-2015 22:16   in response to: JelleWiersma in response to: JelleWiersma
 
  Click to reply to this thread Reply
(Thread moved - it will get more attention here.)
monkeyboy

Posts: 83
Registered: 21-Jun-2008
Re: data from disk to JTextArea problem
Posted: 27-Jul-2015 22:37   in response to: JelleWiersma in response to: JelleWiersma
 
  Click to reply to this thread Reply
The setText() method expects a String but you are giving it a StringBuilder.
Try:
righttextAreaTemplate.setText(sb.toString());
JelleWiersma

Posts: 4
Registered: 31-May-2006
Re: data from disk to JTextArea problem
Posted: 28-Jul-2015 08:39   in response to: monkeyboy in response to: monkeyboy
 
  Click to reply to this thread Reply
thank you for your suggestion, but with a string builder it still does not work.
if i change the stringbuilder to String it works.
problem solved.

thank you.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums