0

If I want something like this to appear:

+---------------------------------------+   
|                                       |                           

I have to put it it in notepad ++ as

System.out.println("+------------------------------------------------+");  
System.out.println("|                               |");  

Is there a way to make the output appear as it does in the text editor? I read that it could be because of tabs/spaces being mixed, but I made sure to only use space-bar.

2 Answers2

2

It is the same text. It isn't the same font.

Use a monospaced font in the text area (and Notepad++):

A monospaced font, also called a fixed-pitch, fixed-width or non-proportional font, is a font whose letters and characters each occupy the same amount of horizontal space. This contrasts with variable-width fonts, where the letters differ in size from one another.


See SWT - OS agnostic way to get monospaced font

Community
  • 1
  • 1
user2864740
  • 60,010
  • 15
  • 145
  • 220
  • Courier seems to be monospaced http://en.wikipedia.org/wiki/Samples_of_monospaced_typefaces and that is the font I am using. – user3029479 Nov 24 '13 at 23:35
  • @user3029479 It is. However, I believe the above is still accurate. Notepad++ won't write tabs - or other kinds of spaces - in strings on its own. Also, writing to `out` is not the same as writing to a JTextArea(?) which is .. an odd way to show the issue. – user2864740 Nov 24 '13 at 23:37
  • If Courier is a monospaced font, than why can't I just use that? I am just starting to learn programming so System.out.println is just what I was told to do. – user3029479 Nov 24 '13 at 23:48
  • Also I don't know where to add (this is the answer from your link). Just in the regular program? Font mono = new Font(parent.getDisplay(), "Monospaced", 10, SWT.NONE); – user3029479 Nov 24 '13 at 23:55
  • 1
    I messed around with the Fonts and themes and it fixed itself. – user3029479 Nov 25 '13 at 00:10
1

if it really bothers you:

public String myFormat(int len, char ch, char margin) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append(margin);
    for (int i = 0; i < len; i++) {
        stringBuilder.append(ch);
    }
    stringBuilder.append(margin);
    return stringBuilder.toString();
}

System.out.println(myFormat(20, '-', '+'));
System.out.println(myFormat(20, ' ', '|'));

just an idea...

Guy Gavriely
  • 11,228
  • 6
  • 27
  • 42