I need to display a JLabel text in this format.
Hoffenheim 1 : 0 Koeln
Bayern 2 : 1 HSV
I just can't get this done. I've tried String.format()
without luck.
Any advice?
You can use HTML. Read How to Use HTML in Swing Components for details. For example you could build a table, similar to the following:
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class StringDemo {
public static void main(String arg[]){
StringBuilder buff = new StringBuilder();
buff.append("<html><table>");
buff.append(String.format("<tr><td align='right'>%s</td><td>:</td><td>%s</td></tr>", "Hoffenheim 1", "0 Koeln"));
buff.append(String.format("<tr><td align='right'>%s</td><td>:</td><td>%s</td></tr>", "Bayern 2", "1 HSV"));
buff.append("</table></html>");
JOptionPane.showMessageDialog(null, new JLabel(buff.toString()));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With