Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-05-2008, 08:17 PM
Member
 
Join Date: May 2008
Posts: 3
Gakusei is on a distinguished road
[SOLVED] \t not working correctly?
Hi everyone, I'm having a bit of trouble with "\t" for some reason.

This is what I'm trying to output:

Code:
N 10*N 100*N 1000*N 1 10 100 1000 2 20 200 2000 3 30 300 3000 4 40 400 4000 5 50 500 5000
My code works fine except that it doesn't put the tab doesn't show up.
Here is my code:

Code:
import javax.swing.JOptionPane; public class Ex6 { public static void main(String args[]) { String msg; msg = "N\t10*N\t100*N\t1000*N\n\n"; // \t doesn't seem to be working for some reason... for (int i = 1; i <= 5; i++) { msg += String.format("%d\t%d\t%d\t%d\n", i, i*10, i*100, i*1000); } JOptionPane.showMessageDialog(null, msg); } }
And this is what I get:

Code:
N10*N100*N1000*N 1101001000 2202002000 3303003000 4404004000 5505005000
Does anyone happen to know what the problem is here?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-05-2008, 10:49 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 183
danielstoner is on a distinguished road
Actually it works but not in the GUI. It works at the console.

Code:
import javax.swing.JOptionPane; public class Ex6 { public static void main(String args[]) { String msg; msg = "N\t10*N\t100*N\t1000*N\n\n"; // \t doesn't seem to be working for some reason... for (int i = 1; i <= 5; i++) { msg += String.format("%d\t%d\t%d\t%d\n", i, i * 10, i * 100, i * 1000); } System.out.println(msg); JOptionPane.showMessageDialog(null, msg); } }
__________________
Daniel @ [
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-06-2008, 02:08 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,017
hardwired is on a distinguished road
Code:
import javax.swing.JOptionPane; public class Ex6Rx { public static void main(String args[]) { String msg; msg = String.format("%11sN%9s10*N%5s100*N%3s1000*N\n", "", "", "", ""); for (int i = 1; i <= 5; i++) { msg += String.format("%12d%12d%12d%12d\n", i, i*10, i*100, i*1000); } JOptionPane.showMessageDialog(null, msg, "", -1); } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-06-2008, 02:46 PM
Member
 
Join Date: May 2008
Posts: 3
Gakusei is on a distinguished road
Weird that it works in the console but not in the GUI.

Thanks for the reply, hardwired, that method worked. It also worked when I used the tab key in place of the "\t"s.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-06-2008, 04:28 PM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 508
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Quote:
String.format("%d\t%d\t%d\t%d\n", i, i*10, i*100, i*1000);
Have you tried also to put some whitespace?

Like,
Quote:
%d \t %d \t %d \t %d\n
Have you also test it like that?
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by sukatoa : 05-06-2008 at 04:33 PM.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-06-2008, 05:45 PM
Member
 
Join Date: May 2008
Posts: 3
Gakusei is on a distinguished road
I just tried doing with the whitespace

Quote:
%d \t %d \t %d \t %d\n
The spaces show up, but it seems like \t is completely ignored.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
requestFocusInWindow() not working Iyengar AWT / Swing 2 03-24-2008 02:35 AM
DynaValidatorForm isn't working Peter Web Frameworks 3 02-15-2008 12:14 PM
sendredirect not working ranga Java Servlet 0 02-11-2008 11:48 AM
How Do I Embed Java Correctly To A Web Page abcd Java Applets 7 01-28-2008 08:53 AM
Working With ANT JavaForums Eclipse 0 04-26-2007 09:16 PM


All times are GMT +3. The time now is 11:38 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org