Solved

Creating a white space

Posted on 2002-06-26
5
175 Views
Last Modified: 2010-03-31
Is there an existing class in Java wherein I can use just say create 50 spaces and start displaying a string in the text Area?

I don't like to create a method that just loop and create a space with append the string I want.
0
Comment
Question by:bubwit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Accepted Solution

by:
Calron earned 20 total points
ID: 7112844
You probably need this to set the initial size of the TextArea, instead of just filling in spaces, you can also use the methods: setColumns(int), be sure to read the API doc of the setColumns(int) and getColumnWidth() as setting the number of columns is not the same as allowing for n characters.

If you still want to use spaces, there is no ready made class, I would do the loop, though make sure you don't loop on a String (way too slow and creates a ton of temporary string objects), use StringBuffer:

StringBuffer s = new StringBuffer();
for (int i = 0; i < 50; i++) {
  s.append(" ");
}
String finalString = s.toString();


of course you can make this more efficient by adding 2 or more spaces at a time, its just supposed to be an example
0
 
LVL 92

Expert Comment

by:objects
ID: 7112929
This should be a bit faster:

char[] spaces = new char[50];
Arrays.fill(spaces, ' ');
String s = new String(spaces);
0
 

Expert Comment

by:udaykumar22
ID: 7115965
Hi,

I think this would be the fastest ;-)

String Str = new String("                                                 ");

Regards,
Uday.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8893423
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to Calron

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question