Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a Java Expert!

Join 307,153 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,674 people online right now. Registration is fast and FREE... Join Now!




Wrap around in a JoptionPane

 

Wrap around in a JoptionPane, can u wrap around

RETNE

18 Sep, 2009 - 04:45 AM
Post #1

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 29


My Contributions
Can a Joption Pane be made to wrap around after its width exceeds a certain value

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 6)

macosxnerd101

RE: Wrap Around In A JoptionPane

18 Sep, 2009 - 04:55 AM
Post #2

Self-Trained Economist
Group Icon

Joined: 27 Dec, 2008
Posts: 1,884



Thanked: 208 times
Dream Kudos: 325
Expert In: Java

My Contributions
You can use the \n character literal for a line break.
User is offlineProfile CardPM
+Quote Post

RETNE

RE: Wrap Around In A JoptionPane

18 Sep, 2009 - 05:01 AM
Post #3

New D.I.C Head
*

Joined: 17 Nov, 2007
Posts: 29


My Contributions
The problem is that im reading from a data file and everything i need to be read is on one line

I cant separate them into individual fields because then i wont know how many lines im gona need for the JoptionPane every time the information changes

User is offlineProfile CardPM
+Quote Post

KYA

RE: Wrap Around In A JoptionPane

18 Sep, 2009 - 05:03 AM
Post #4

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 11,500



Thanked: 508 times
Dream Kudos: 2875
Expert In: C, C++, Java

My Contributions
Concatenate a string from your data input.
User is online!Profile CardPM
+Quote Post

William_Wilson

RE: Wrap Around In A JoptionPane

18 Sep, 2009 - 05:07 AM
Post #5

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,668



Thanked: 97 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
you can write it to a hidden label and use the FontMetrics class to get the width, to which you can use to determine where to insert a line break.

Personally I would set a maximum character length per line and insert the newlines on the first space character previous to that length.
User is offlineProfile CardPM
+Quote Post

macosxnerd101

RE: Wrap Around In A JoptionPane

18 Sep, 2009 - 05:10 AM
Post #6

Self-Trained Economist
Group Icon

Joined: 27 Dec, 2008
Posts: 1,884



Thanked: 208 times
Dream Kudos: 325
Expert In: Java

My Contributions
I agree w/KYA. Read in your data as a String, convert it to a StringTokenizer, and then feed the individual tokens into your JOptionPane. If the approximate length of each token is the same, then you can simply add a carriage return on an interval.
User is offlineProfile CardPM
+Quote Post

pbl

RE: Wrap Around In A JoptionPane

18 Sep, 2009 - 01:15 PM
Post #7

Java Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 9,966



Thanked: 1188 times
Dream Kudos: 450
My Contributions
Convert your string into a char[] array then after a certain number of character replace the first ' ' by a '\n' and start again

CODE

int maxByLine = 60;
char[] digit = line.toCharArray();
int count = 0;
for(int i = 0; i < digit.length; i++) {
    count++;
    if(count > maxByLine) {
       if(digit[i] == ' ') {
          digit[i] = '\n';
          count = 0;
       }
    }
}
line = new String(digit);

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 04:54PM

Live Java Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month