-1

I need to print a list of teams in a JLabel, so I'd like to order each of them in a different lane but when I try my code it seems like the "\n" part if the code doesn't work. I've been reading a bit and many solutions show that it needs to be inside HTML tags. I've tried and no solutions I got.

private void terminarEquiposActionPerformed(java.awt.event.ActionEvent evt) {                                                
    if(listadoEquipos.size() < numEquipos){
        this.aviso.setText("Faltan " + (numEquipos-listadoEquipos.size()) + " equipos.");
    }else{
        this.jDialogEquipos.setVisible(false);
        this.jPanel1.setVisible(true);
        String lista = "";
        for(int i = 0; i < listadoEquipos.size(); i++){
            lista += (i+1) + " : " +  listadoEquipos.get(i).getNombre() + '\n';   //TODO saltos de linea en jLabel
        }
        this.imagenUEFA.setText(lista);
        contador = 0;
    }
}

The ArrayList listadoEquipo contains the names I need to show and I use the String lista for building the result I want to show in the label imagenUEFA.

I'm not allowed to share png yet but when I run I got this:

At the left of the picture there's the label to show the name of the teams and the rest of picture are buttons for the activity

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Ivan
  • 21
  • 4
  • 1) For better help sooner, [edit] to add a [mre]. 2) A `JLabel` supports (very basic) HTML. It seems an ordered list (`
      `) would suit this well. 3) *"..inside html tags. I've tried and no solutions I got."* Well, apparently the HTML used was .. incorrect. See point (1).
    – Andrew Thompson Jan 08 '22 at 16:20

1 Answers1

0

After a more few minutes searching for a solution, I found it:

private void terminarEquiposActionPerformed(java.awt.event.ActionEvent evt) {   
    if(listadoEquipos.size() < numEquipos){
        this.aviso.setText("Faltan " + (numEquipos-listadoEquipos.size()) + " equipos.");
    }else{
        this.jDialogEquipos.setVisible(false);
        this.jPanel1.setVisible(true);
        String lista = "<html><pre>";
        for(int i = 0; i < listadoEquipos.size(); i++){
            lista += (i+1) + " : " +  listadoEquipos.get(i).getNombre() + "\n";   //TODO saltos de linea en jLabel
        }
        lista += "</pre></html>";
        this.imagenUEFA.setText(lista);
        contador = 0;
    }
}

I added the tag <pre> between the HTML ones so the run seems like this:

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Ivan
  • 21
  • 4