swing - Java (JLabel spacing) -
i want jlabel display "hi, name bob"
however, when coded: jlabel.settext("hi, name bob");
the spaces "consumed" , output read "hi, name bob"
can please me on this? in advance
here 2 ways both have same effect. 1 sets font monospaced
while other marks text html preformatted (which uses monospaced font & preserves spaces , tabs).
string text = "hi, name bob"; // ... jlabel l = new jlabel(text); l.setfont(new font(font.monospaced, font.plain, l.getfont().getsize())); ui.add(l); ui.add(new jlabel("<html><body><pre>" + text));
having said that, agree @madonah & @maraca best handled in 2 labels, using layouts (borders , padding) achieve required result.
Comments
Post a Comment