Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 13th, 2004, 03:51 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Console output rewriting

Hello,
  I am trying to write a Java app which outputs progress information to the command line (principally in windows, but I would like a cross-platform solution), and obviously I am using System.out for this. However, I would like to write a progress bar (like the scp progress bar) which writes to the same line on the console over and over.

  How can this be achieved?

  holdmykidney
 
Old November 3rd, 2004, 01:57 PM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You could use "\r" to take you back to the beginning of the line, then overwrite like:

import java.io.*;

class tmp {
        public static void main (String argv[]) {
                System.out.print ("hello\rgoodbye");
        }
}

or you could use backspaces in the same way, which might be more portable

import java.io.*;

class tmp {
        public static void main (String argv[]) {
                System.out.print ("Hallo\b\b\b\b\bGoodbye");
        }
}

--
Don't Stand on your head - you'll get footprints in your hair. http://charlieharvey.com
 
Old November 15th, 2004, 09:07 AM
Authorized User
 
Join Date: Jul 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Spectacular. That works exactly as required.

As a footnote, it is worth pointing out that in the windows environment I was using if you write to the very last column of text, it automatically performs a line-feed, so for this to work you have to operate within the first 79 characters.
Is this correct?
Also, is there an automatic method for determining the console width? (eg. System.getProperty)

holdmykidney
 
Old November 26th, 2004, 12:16 PM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

oh yeh, hadn't thought of that. don't know if there is a way of finding that out. anyone else?

--
Don't Stand on your head - you'll get footprints in your hair. http://charlieharvey.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect Console Output(VB.Net) danasegarane Visual Studio 2005 1 September 9th, 2007 10:30 AM
Console application but no Console gamotter C# 2 August 22nd, 2007 11:41 PM
URL Rewriting Amateur BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 August 9th, 2007 01:54 AM
Discussion: URL Rewriting planoie ASP.NET 1.x and 2.0 Application Design 2 January 25th, 2006 03:38 PM
Problem with First.cs output via Console.WriteLine patrick764 C# 1 November 7th, 2005 03:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.