0

I have 3 Arrays of TextList and everytime a button is pressed, the text will appear one after another. However, The next text appears beside the previous text. I would like the next text to appear below instead. I tried using <html> and <p> but instead they appear with the text. How do i make the text to appear below instead of beside each other? This is my sample of code.

    textList.add("<html> Testing");
    textList.add("<p> asdasdssss<p>ssssssssssssa<p>dssad");
    textList.add("\n lmaoasdasasd" + "</html>");


    JLabel hint = new JLabel("");
    hint.setBounds(29, 21, 395, 134);
    panel.add(hint);


    JButton btnHint = new JButton("hint");
    btnHint.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            hint.setText(hint.getText() + "\n" + textList.get(textIndex++));
        }
    });
user85421
  • 28,957
  • 10
  • 64
  • 87
  • Use ``\r\n`` instead of ``\n`` or format the thing using html tags.. – f1sh Feb 01 '17 at 10:43
  • Incrementing `textIndex` without checking it will throw IndexOutOfBounds eventually – Daniel Puiu Feb 01 '17 at 10:47
  • yep it will throw an error after the 3rd click, however right now the problem is i tried using ,

    , \n,
    tags in my textList strings but they appear with the string instead.

    – Rui Isolet Feb 01 '17 at 10:48

1 Answers1

-1

Html tag < p> requires a closing <\p> try using tag < br> which does not require closing tag. This tag means "break" which means new line. Use this great HTML tutrial to learn HTML "on the fly"

Michael Gantman
  • 7,315
  • 2
  • 19
  • 36
  • "
    which does not require closing tag" is a horrible advice. Every tag needs to be closed, use ``
    `` instead.
    – f1sh Feb 01 '17 at 10:52
  • Actually according to the best rated answer to this question: http://stackoverflow.com/questions/1946426/html-5-is-it-br-br-or-br tag
    is completely valid. you voted me down unfarely
    – Michael Gantman Feb 01 '17 at 11:33
  • Also, to even further prove my point look here: http://www.w3schools.com/tags/tag_br.asp – Michael Gantman Feb 01 '17 at 11:36