-3

I just can't get it to work, I need to make my text bold, but everything I see on Google doesn't work.

This is my code:

drawLoadingText(percentage, (new StringBuilder()).append("Downloading "+downloadingText+""+s+": "+percentage+"% ").append("@ "+downloadSpeed+"Kb/s").toString());
TylerH
  • 20,799
  • 66
  • 75
  • 101
Mitchell Antes
  • 1
  • 1
  • 1
  • 2
  • 5
    `Hope anyone can help me out!` - how do you expect anybody to be able to help you without knowing the context of your question? Are you trying to display bold text on the console? Are you using Swing (or some other GUI? Are you displaying the text in a Swing component? Are you doing custom painting? Update your question to make it more reasonable. – camickr Oct 18 '15 at 19:59

2 Answers2

1

Unclear what should be bold. But you could surround it with a <b> and </b> (there are a few assumptions in this statement1). Finally, I would prefer a call to String.format(String, Object...) for implementing formatted text. Something like

drawLoadingText(percentage, String.format(
        "Downloading <b>%s</b> %s: %d%% @ %d KB/s", downloadingText, s,
        percentage, downloadSpeed));

1 Basically, I assumed you're drawing some text using a standardish JComponent.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
0

I have looked for this fo java code using ASCII table.

\u001B[1m <- Bold on

\u001B[0m <- Text Stuffs off

drawLoadingText(percentage, (new StringBuilder()).append("\u001B[1mDownloading\u001B[0m "+downloadingText+""+s+": "+percentage+"% ").append("@ "+downloadSpeed+"Kb/s").toString());

this above its find here

In order to apply a style on your string, you can use a command like:

echo -e '\033[1mYOUR_STRING\033[0m'

Explanation:

echo -e - The -e option means that escaped (backslashed) strings will be interpreted

\033 - escaped sequence represents beginning/ending of the style lowercase m - indicates the end of the sequence

1 - Bold attribute (see below for more)

[0m - resets all attributes, colors, formatting, etc.

The possible integers are:

0 - Normal Style

1 - Bold

2 - Dim

3 - Italic

4 - Underlined

5 - Blinking

7 - Reverse

8 - Invisible

Leon Volt
  • 1
  • 1