reading \n from a file  
Author Message
V S Rawat





PostPosted: 2004-6-22 2:23:00 Top

java-programmer, reading \n from a file I am reading from a file and storing in String.

I need to separate a word so that part of it goes to next line

abc\nxyd

I am moving this text to button.setText() and this should
appear on the button as

abc
xyz

for that I am putting newline escape there.

it is not working. I have tried putting unicode string in
place of \n that also is not working.

how to do it?

-Rawat

 
Andrew Thompson





PostPosted: 2004-6-22 15:49:00 Top

java-programmer >> reading \n from a file On Mon, 21 Jun 2004 23:53:15 +0530, V S Rawat wrote:
..
> I need to separate a word so that part of it goes to next line
>
> abc\nxyd
>
> I am moving this text to button.setText() and this should
> appear on the button as

AWT or Swing?
 
V S Rawat





PostPosted: 2004-6-22 16:44:00 Top

java-programmer >> reading \n from a file Andrew Thompson wrote:
> On Mon, 21 Jun 2004 23:53:15 +0530, V S Rawat wrote: ...
>
>> I need to separate a word so that part of it goes to
>> next line
>>
>> abc\nxyd
>>
>> I am moving this text to button.setText() and this
>> should appear on the button as
>
>
> AWT or Swing?

well.

I am going to use that to set text on jbuttons in a
gridbaglayout. that makes it swing, but please suggest.

The main program I am working with is already having these
at the very beginning:

import java.awt.*;
import java.io.*;
import java.util.*;
import java.net.*;
import java.awt.event.*;
import java.awt.print.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.text.rtf.*;

If anything else is required to enable the above, I can
include that too.

-Rawat

 
 
joeking





PostPosted: 2004-6-22 20:17:00 Top

java-programmer >> reading \n from a file V S Rawat <""<vsrawat no reply \"@hclinfinet.com>> wrote in message news:<email***@***.com>...
> I am reading from a file and storing in String.
>
> I need to separate a word so that part of it goes to next line
>
> abc\nxyd
>
> I am moving this text to button.setText() and this should
> appear on the button as
>
> abc
> xyz
>
> for that I am putting newline escape there.
>
> it is not working. I have tried putting unicode string in
> place of \n that also is not working.
>
> how to do it?


Under AWT I don't think it is possible, other than writing your own
lightweight button.

Under Swing "<html>abc<br>xyz</html>" might just work! :-)

-FISH- ><>
 
 
Andrew Thompson





PostPosted: 2004-6-22 22:42:00 Top

java-programmer >> reading \n from a file On Tue, 22 Jun 2004 14:14:20 +0530, V S Rawat wrote:

> abc\nxyd
> >> I am moving this text to button.setText() and this
> >> should appear on the button as
...
> > AWT or Swing?
..
> I am going to use that to set text on jbuttons

new JButton("<html><body>abc<br>xyd</body></html>")

>..in a
> gridbaglayout.

That is usually a bad choice, but
sometimes is becessary, I have
coded many GUI's, but only the
Periodic Table required a GBL..

> The main program I am working with is already having these
> at the very beginning:
<snip imports>

> If anything else is required to enable the above, I can
> include that too.

You might get some value from understanding
the advantages of providing a self
contained (short!) example..
<http://www.physci.org/codes/sscce.jsp>

[ For example, if I'd known Swing from your
original question, I would have immediately
suggested you format using HTML.. ]

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
 
V S Rawat





PostPosted: 2004-6-22 22:42:00 Top

java-programmer >> reading \n from a file FISH wrote:
> Under AWT I don't think it is possible, other than
> writing your own lightweight button.
>
> Under Swing "<html>abc<br>xyz</html>" might just work!
> :-)
>
> -FISH- ><>

I was already using <html> on the buttons, hence I just
added <br> in place of \n in the input file.

:) it worked.

An oceanful of thanks.

-Rawat

 
 
nemo





PostPosted: 2004-6-23 0:54:00 Top

java-programmer >> reading \n from a file
"V S Rawat >" <""<vsrawat no reply \"@hclinfinet.com> wrote in message
news:email***@***.com...
> I am reading from a file and storing in String.
>
> I need to separate a word so that part of it goes to next line
>
> abc\nxyd
>
> I am moving this text to button.setText() and this should
> appear on the button as
>
> abc
> xyz
>
> for that I am putting newline escape there.
>
> it is not working. I have tried putting unicode string in
> place of \n that also is not working.
>
> how to do it?
>
> -Rawat
>
>

It might be better to use a comma as a separator,
but using psudeo code:

array = array of strings
read in file one char at a time until EOF
{
if (string compare is /)
{if (string compare is n)
{ increment data array}
}
else
{add char to string in data array}
}

using a comma as a separator would negate the need
for a second if block.
Hope this helps.






----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---