0

I tried:

//All the stuff with JLabel initialization

int Number = 10;
String data = "Value: " + Number;

lbl.setText(data);  //The JLabel says: "Value:..."
System.out.println(data); //The console says: "Value: 10"

How can I fix this? This problem never happened to me before.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Does your label actually have enough space? What happens if you shorten it to `String data = "X: " + Number;`? – Jon Skeet Jul 22 '21 at 07:16
  • What layout manager do you use? Can you show the code regarding "_all the stuff with the JLabel initialization_"? – maloomeister Jul 22 '21 at 07:22
  • _**Why does JLabel convert any nuber in a string to “…” in Java?**_ Did you verify this conclusion ? try `System.out.println(lbl.getText());` – c0der Jul 22 '21 at 08:58
  • Don't use a null layout and setBounds. Swing was designed to be used with [Layout Managers](https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html). The layout manager will determine the proper size of the label so all the text is displayed. – camickr Jul 22 '21 at 13:50
  • Oh I got it, I extended the JLabel and it became normal. – Pritam Pradhan Jul 23 '21 at 03:46
  • I really don't know why does java make the text "..." – Pritam Pradhan Jul 23 '21 at 03:46
  • this is call an ellipsis, this happens if there are more text than the label can extend. This is a generic a widespread mechanic that exists on web technologies and others languages. – Walfrat Sep 09 '21 at 08:08

0 Answers0