Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to output data from RAF in a text area GUI. I am getting output (title is different length, but 35 char max), but all attempts to put String into columns fails.

This is what I currently have:

while (count < noItems) {

    String title = "";
    for (int i = 0; i < 35; i++) {
        title += raf.readChar();
    }

    int noCopies = raf.readInt();
    double price = raf.readDouble();


   result+=String.format("%-40s", title);
   result+=(noCopies+"\t "+ twoDigit.format(price)+"\n"); 
    count++;
}
mainTextArea.setText(result);
share|improve this question
    
Removed excess, Reworded for clarity, Fixed formatting. –  Alex K Mar 7 at 18:18

1 Answer 1

May be you're exceeding maximum length of string (2^31 - 1) as you are adding all columns in one string result (thus all attempts to put String into columns fails). Try to add every columns in JTextArea(mainTextArea) every time in while loop . Try this code,

while (count < noItems) {

String title = "";
for (int i = 0; i < 35; i++) {
    title += raf.readChar();
}

int noCopies = raf.readInt();
double price = raf.readDouble();


result = String.format("%-40s", title) + (noCopies+"\t "+ twoDigit.format(price)+"\n"); 
mainTextArea.setText(result);
count++;

}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.