Line breaks in java

Hi, I'm a little new to Java. I am trying to make a line break that is not in a textbox. So far, to make something similar to a line break, I played with the size of the applet on the HTML file. However, it's not working for one of my applets because it must be in several lines.
I know that you can use /n or /r/n for line breaks in a TextArea, but I need to use line breaks to separate Buttons and several TextFields.
In an earlier forum there was something like this:
System.getProperty("line.separator");
I don't really know how to add the line separator to my code. I pasted that just inside
public class ClassName extends java.applet.Applet
implements ActionListener
right before
public void init( )
I tried putting "line.separator" in a string, but it did not work
I also tried the following:
add(/n);
add(/r/n);
add(line.separator);
but none of them worked.
If someone could help me, I would very much appreciate it. Thanks!

I don't know why I didn't think of that, but there's an error when I compile it.
SquareRoot.java:21: cannot find symbol
symbol : method add(java.lang.String)
location: class SquareRoot
add(System.getProperty("line.separator"));
^
And the same thing happens when I try it with \n
SquareRoot.java:21: cannot find symbol
symbol : method add(java.lang.String)
location: class SquareRoot
add("\n");
^
Here's the code:
public class SquareRoot extends java.applet.Applet
     implements ActionListener
     TextField m1, m2;
     Button b;
     double i1, i2, i3, i4;
     public void init( )
          m1 = new TextField(20);
          m2 = new TextField(20);
          b = new Button("Calculate");
          add(m1);
          add("\n");  //I'm trying to add a line break here
          add(b);
          add(m2);
          b.addActionListener(this);
     }Thanks!

Similar Messages

  • Line Break in Java for writing to a file

    Hi
    I am writing some data from excel sheet to a text file. I am using POI for reading the data from excel sheets.
    Whenever i encounter a value in the cell i want to add it to the text file.. this works fine
    But when its a new row(in excel sheet), i want it to be printed on a new line in the text file.
    Does anyone have a suggestion how can i move the cursor to the next line?
    Also i am taking the excel file from user and have to convert it to a tab limited file after some checking.
    As anyone done this before & would like to share some experience or have some suggestions?
    Thanx

    Hi paul
    Thanx for your reply. ('\n') works for the next line and I am using ('\t') for tabs between columns
    I had one more question.
    Can anyone tell me how i can write int values to the file?
    My excel sheet has String, numeric, String, String, String data
    From POI HSSF i get the string values as String, and i am casting the numeric values to int (since POI hssf returns double)
    When addind data to the file, the string values are taken fine.. but not the numeric values.. a '?' is put instead of the int value (which is 4 -6 digit long)
    DO i have to change to char buffer or something?
    Please let me know

  • Printing with line breaks

    Hi,
    I am using the following code to print some text from a text file.
    import java.awt.*;
    import java.awt.font.*;
    import java.awt.geom.*;
    import java.awt.print.*;
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.FileInputStream;
    import java.io.InputStreamReader;
    import java.text.*;
    public class Print implements Printable {
    private static final String mText = "";
    private static AttributedString mStyledText = new AttributedString(mText);
        static public void main() {
            String toPrint = "";
            try {
                FileInputStream fstream = new FileInputStream("/Library/iDemo/print.txt");
                DataInputStream in = new DataInputStream(fstream);
                BufferedReader br = new BufferedReader(new InputStreamReader(in));
                String strLine;
                while ((strLine = br.readLine()) != null) {
                    toPrint = toPrint + System.getProperty("line.separator") + strLine;
                in.close();
            } catch (Exception e)
                System.err.println("Error: " + e.getMessage());
            mStyledText = new AttributedString(toPrint);
            PrinterJob printerJob = PrinterJob.getPrinterJob();
    Book book = new Book();
    book.append(new Print(), new PageFormat());
    printerJob.setPageable(book);
    boolean doPrint = printerJob.printDialog();
    if (doPrint) {
    try {
    printerJob.print();
    } catch (PrinterException exception) {
    System.err.println("Printing error: " + exception);
    public int print(Graphics g, PageFormat format, int pageIndex)
    Graphics2D g2d = (Graphics2D) g;
    g2d.translate(format.getImageableX(), format.getImageableY());
    g2d.setPaint(Color.black);
            Point2D.Float pen = new Point2D.Float();
            AttributedCharacterIterator charIterator = mStyledText.getIterator();
            LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, g2d.getFontRenderContext());
            float wrappingWidth = (float) format.getImageableWidth();
            while (measurer.getPosition() < charIterator.getEndIndex())
                TextLayout layout = measurer.nextLayout(wrappingWidth);
                pen.y += layout.getAscent();
                float dx = layout.isLeftToRight() ? 0 : (wrappingWidth - layout.getAdvance());
                layout.draw(g2d, pen.x + dx, pen.y);
                pen.y += layout.getDescent() + layout.getLeading();
            return Printable.PAGE_EXISTS;
    }The problem I am having is that it removes the line breaks when printing. I have checked the file I am reading from and that has the line breaks. How can I get it to include the line breaks?
    Thanks

    The problem is that once it prints all this the line break is gone.
    Up until the following code the line breaks are fine. However, the printed document I'm getting has no line breaks at all.
    mStyledText = new AttributedString(toPrint);
            PrinterJob printerJob = PrinterJob.getPrinterJob();
    Book book = new Book();
    book.append(new Print(), new PageFormat());
    printerJob.setPageable(book);
    boolean doPrint = printerJob.printDialog();
    if (doPrint) {
    try {
    printerJob.print();
    } catch (PrinterException exception) {
    System.err.println("Printing error: " + exception);
    public int print(Graphics g, PageFormat format, int pageIndex)
    Graphics2D g2d = (Graphics2D) g;
    g2d.translate(format.getImageableX(), format.getImageableY());
    g2d.setPaint(Color.black);
            Point2D.Float pen = new Point2D.Float();
            AttributedCharacterIterator charIterator = mStyledText.getIterator();
            LineBreakMeasurer measurer = new LineBreakMeasurer(charIterator, g2d.getFontRenderContext());
            float wrappingWidth = (float) format.getImageableWidth();
            while (measurer.getPosition() < charIterator.getEndIndex())
                TextLayout layout = measurer.nextLayout(wrappingWidth);
                pen.y += layout.getAscent();
                float dx = layout.isLeftToRight() ? 0 : (wrappingWidth - layout.getAdvance());
                layout.draw(g2d, pen.x + dx, pen.y);
                pen.y += layout.getDescent() + layout.getLeading();
            return Printable.PAGE_EXISTS;
    }

  • Line wrapping in Java??

    Hi,
    Can anyone tell me if there is a class to handle line wrapping in Java?
    I'm working on a Java Mail application that deals with fairly lengthy email message bodies. The problem is in the actual email, the message body appears in a lengthy horizontal single line which is rather inconvenient to read.
    I'd like to break the message body into convenient 80 character lines that takes word boundries into account so that there are no broken words at the end of a line.
    Thanks,
    Veena

    Well the easiest way would be to put line breaks when you want them.
    "\n" is the line break character.
    So String("aaaaa\naaaaa");
    Should appear as
    aaaaa
    aaaaa

  • Calculating line length in Java

    Hi all;
    I've been using LineBreakMeasurer & AttributedString to measure line lengths. However, I now need to take into account:
    Small Caps
    Scaling (making each character thinner/wider).
    Spacing (adding/subtracting space after each character).
    Hyphenation, where line breaks can occur at specific places within words.
    Is there a way to do this using Java? The two fundamental things I need to get is:
    How long is a passed in string.
    For a passed in string and length, how many characters of the string fits in that length.
    I can do this using LineBreakMeasurer & AttributedString and calling it character by character. But is there a better way?
    thanks - dave

    Hi, Have you had a look at the FontMetrics class? That might be an option.

  • File Streams *creating Files without those pesky line breaks

    Greetings Java Developers,
    Basicly I would like to write a large block of data out to a file without any line breaks and end of line characters that most JAVA Output Streams include with each call to WRITE(); First I am using BYTE Output Streams in JAVA and two end of line bytes are written also!!!
    It may be possible to use a Buffered File Stream with a Large Buffer about a Megabyte or so and FLUSH() the Stream all at once.
    Any ideas or suggestions will be greatly appreaciated!
    -chibi_neko

    I have not had a problem writing bytes to file. The getStream call returns a FileOutputStream. Also note that the curly braces around 'i' really are square braces but I used them because square braces around I get reformatted in his post.
          * Write bytes to a file.
          @param Data Data to write to a file.
          @param file Destination file.
         public static void write(byte [][] Data, File file)
              try
                   OutputStream out = getStream(file);
                   for(int i = 0 ; i < Data.length ; i++)
                        out.write(Data{i});
                   out.close();
              catch(IOException E)
                   throw new Error(E.getMessage());
              catch(Exception e)
                   throw new Error(e.getMessage());
         }the getStream method
    FileOutputStream fw = new FileOutputStream(file.getPath(),append);

  • Very Simple: How do I programmatically add line breaks?

    Very Simple: How do I programmatically add line breaks or how do I encapsulate my RichCommandLink's within a paragraph?
    My Code is as follows:
    for (String token : userViews.getViewNames())
    // add command link
    RichCommandLink output = new RichCommandLink();
    output.setText(token);
    // set action here
    // output.setActionExpression());
    viewItem.getChildren().add(output);
    // update view
    this.menuAccordion.getChildren().clear();
    this.menuAccordion.getChildren().add(0, viewItem);
    AdfFacesContext.getCurrentInstance().addPartialTarget(getMenuAccordion());

    Sorry, I'm using Jdeveloper 11.
    Im using JSP, JSF, ADF, Fusion. The RichCommandLink is an ADF Control.
    My PanelAccordion is bound to a RichPanelAccordion in my java class. When I add RichCommandLink's to the accordion the items are added next to each other. How do I add line breaks from my java class?

  • Hard Line Breaks in JEditorPane

    Hello All - How can I create hard line breaks in a JEditorPane's document with HTMLEditorKit after a line wraps. In other words, I'd like to see a <br> when the cursor moves to the next line.
    Please Help !
    Norman

    Your answer is in your question....This is an old post and the OP had already been given the correct answer at the link shown below:
    http://forum.java.sun.com/thread.jsp?thread=482553&forum=57&message=2251721
    ;o)
    V.V.

  • How to make a String with a line break?

    I want to insert a line break into a strhing...i am trying to do this using a Stringbuffer the following way:
    name = new StringBuffer().append("something").append('\n').append("else").toString();
    but it doesnt' seem to be working.
    any suggestions??
    Andrew

    that was just an example for testing purposes...if
    you read my posts.....
    i said:
    "i am passing a string to my corel template creator
    which is made in java and creates a template in Corel
    Draw.
    but when the string is being passed to the template
    creator i want it to be able to distinguish whether
    the string is supposed to be 2 lines or 1."
    i see zero correlation between that and HTML
    AndrewYour posts thus far strongly suggest that this text will utimately be HTML that will be rendered by a browser. I don't know what this Corel template is, but based on the other stuff you've said, I assumed it was some sort of HTML page template.
    If the text will ultimately be HTML that is rendered by a web browser, then the Corel stuff is irrelevant (unless the Corel template is a JSP or other dynamic page generator that lets you specify by some other means where to put line breaks, in which case you need to look at Croel's docs), and you need to insert <br> or <p> or use <pre> tags.
    If the Corel template is some sort of Java widget and you won't be rendering HTML with a web browser, then look at the docs for the Corel template, or contact Corel tech support.

  • Reg Exp help needed (trouble with line breaks)

    Hello,
    I am attempting to parse a line of text with regular expressions. I am having difficulty with the line breaks.
    I want to divide the following line by the first '\n' char.
    For instance, I wan the output to be as follows:
    found 1: one
    found 2: ddd
    dddHowever, I get the following with my attached code:
    found 1: one
    found 2: dddHowever, the second line break seems to be the end of the second group.
    How do I get the any character '.' to read past any subsequent line breaks?
    import java.util.regex.*;
    public class Test
         String rawSequenceArg = ">one\nddd\nddd";     
           Pattern p = Pattern.compile(">([^\n]+)\n(.+)");
           Matcher m = p.matcher(rawSequenceArg);
           if(m.find())
                System.out.println("found 1: " + m.group(1));
                System.out.println("found 2: " + m.group(2));
    }

    In this case, the DOTALL flag is the one you need; it allows the dot (period, full stop) to match line separator characters. MULTILINE makes the '^' and '$' anchors match the beginning and end of logical lines, instead of just the beginning and end of the input.

  • Line Breaks in JAR Manifest

    I'm currently using a maven plug-in to generate a manifest file using the java.util.jar API. When creating attributes in the manifest, the plug-in inserts line breaks in comma-separated lists automatically to make the Manifest easier to read. When the manifest is written using Manifest.write(OutputStream), line breaks are added every 72 characters despite the fact that the attribute value already contains line breaks.
    Should this be reported as a bug or is there another way to format the manifest so that the line breaks don't destroy the readability.
    From the generated manifest:
    Bundle-ClassPath: lib\spring-beans-2.0.7.jar,
    lib\commons-logging-1.
    1.jar,
    lib\log4j-1.2.14.jar,
    lib\spring-core-2.0.7.jar,
    lib\spr
    ing-context-2.0.7.jar,
    lib\spring-dao-2.0.7.jar,

    Manifest lines must not exceed 72 bytes; see
    http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#JAR%20Manifest
    Presumably Manifest.write could try harder to break at commas. You could file an RFE if this is really important and there's not already a similar issue.
    Thanks,
    Dave

  • NOOB Question: Insert a line break ( br or p )

    Hi,
    I try my first steps with webdynpro and find it a bit crazy.
    I now have created my first webapp and it rules but I have 2 questions:
    1. I have 10 elements, which are displayed all abreast, but I want at some elements a line break (<br> or <p>, I only have the solution with FormattedTextView where I can insert html)
    2. How I can add JavaScript-Functions and otherwise <html>-code? CSS-Tags and so on... Have I actually influence of the generated HTML?
    sorry for this noob-questions.
    Christian

    Hi
    In Web Dynpro You can not write HTML , Java Script or insert any CSS code.
    It is not possible.
    If you want a line break between UI elements, you should follow Layouts
    you have different types of Layouts
    1. Matrix Layout
    2. Grid Layout
    3. Row Layout
    4. Flow Layout
    You can control your layout only using the above options.
    Abhi

  • Exporting EPUB from InDesign CC not including line breaks

    I am done with a book and have it formatted the way I want. I am exporting it to EPUB through InDesign CC and previewing it in iBooks and also through Kindle previewer. Everything is fine except for one thing... where I have created page breaks, the exported file is not including them.
    I tried exporting to HTML just to see what it did and there is no line breaks there. I know its proprietary markup ( in kindle ) but I still would like to include them in a few specific places ( to mark seperations of chapters ).
    In kindle this is the tag they say to use: <mbp:pagebreak />
    In iBooks, I have not yet figured out how to create them, I am going to work on that today once I sort out the kindle version.
    Is there any way to force it to include line breaks on export. Or alternatively, I could export to HTML but I am having trouble figuring out how to go back to the EPUB format from there and also it didn't include the fonts, so there was other issues to consider as I have a custom font I was using for the headers that looks really good and matches the font on the book cover as well... so I really want to keep that consistent if possible.
    Are there any tricks or things I can try here to improve on my workflow and do a better job of seperating the chapters ?

    Ok, I hadn't tested the advanced options out in the export menu. It works and does so on both the iBooks and Kindle previewer.. which is good news since that is really important to me to try and find a workflow I can update both of these formats from when I continue to work on my book.
    The only strange part is that on some chapters its adding an extra blank page between the chapter and the next. What is odd is that it only happens on some of them (in the iBook reader only, the kindle previewer isn't doing this)
    I am going to look into this more closely but its not a major deal as I would prefer a little seperation in the chapters anyways, its not really a bad thing. It is just hard to figure out why its doing this.

  • How to get a line break

    Hi All,
    How do I get a line break within a particular field?
    My DB structure is that I have 4 columns address_line_1, address_line_2 and so on. I cannot select them as different fields because all of them can be null, in which case i pick it from internal_address_line column.
    I use:
    SELECT DECODE(address_line_1, NULL, internal_address_line, address_line_1 || ', ' || Address_Line_2) as ADDRESS
    But instead of th comma separating the 2 address lines I want a line break so that 2 address lines come in 2 separate lines in the output.
    It doesn't allow me to use chr(10) as a line break and gives an error
    I'm using Reports 2.5
    TIA
    Naveen

    Yes, true.
    How about setting up the sections as:
    Section 1 Introduction ('Section num space introduction' in this example - tab may be better)
    Then generate the Contents.
    Then do a GREP find/change on the document after the contents:
    This will add a forced line break and tab after each section number... You might want to specify a para style in the Find Format box too, so that references to Section xx in body text are not altered.
    If you update Contents after this, you will get the line break and tab in the Contents too.

  • Not sure why line break is not working

    Hi all,
    Here is part of my simple Swing application:
    String text1 = "hello";
    String text2 = "world";
    String text3 = text1+"\n"+text2;
    // have also tried (String text3 = text1+"\n\r"+text2;)
    displayField.setText(text3);I supposed that the text3 in the label field (displayField) would display like this:
    hello
    world
    But not, the text3 just displayed in the same line like this instead: helloworld.
    I am not sure why the line break is not working.

    Use HTML for a multiline JLabel.// String text3 = text1+"\n"+text2;
    String text3 = "<html>" + text1 + "<br/>" + text2 + "</html>";db

Maybe you are looking for

  • HP Updated USB and wireless Lan Failed to install

    my USB Hard drive cant be found and i've noticed the Intel USB 3.0 extensible host controller FAILED to install the update , and also the Ralink Wireless network driver update / LAN also failed to install , i have tryed other USB hard drives and they

  • BPM scenario issue

    hi We have scenario where Messages flow from TIBCO, gets converted into IDOCs in XI and rend it to other SAP system. For some-reason all though messages were in XI but not processed completly, all most every message status set to 'Scheduled for Outbo

  • Partitioning Question - range partition?

    Hello all we have an issue with the amount of data we have in a particular schema that we are using to store production metrics. I have looked at a few options and are now trying to design a solution using partitioning. At a very high level we have d

  • Using JCOP tools under Linux

    Hello. I looked through the older web sites of IBM regarding the usage of JCOP tools under Linux. I am interested in following questions: 1. Is there any separate distributon version of JCOP tools for Linux? 2. Can sample JCOP tools 3.1.2 plugin (for

  • Security update 2013-004 install fails

    Hi I have tried to apply the Security update 2013-004. The SW updates requires a reboot, but the reboot does not work. It means the Mac does not reboot anymore nor can I shutdown the Mac anymore. The only way to switch if off, reboot is to hold the p