How to do it? I need to put a JLabel
sized so as it would contain 1 digit with a default Font
. Is there a way to do it in a platform-independent way?
Asked
Active
Viewed 20 times
0

user3663882
- 6,957
- 10
- 51
- 92
-
What happened when you added one digit to the `JLabel`? How is it not sizing correctly (on which platform)? – Elliott Frisch Apr 18 '16 at 16:52
-
@ElliottFrisch It should stay the same. On any platform. Is it possible? – user3663882 Apr 18 '16 at 16:57
-
Read up on [Physical and Logical Fonts](https://docs.oracle.com/javase/tutorial/2d/text/fonts.html). Specifically, the section on "Lucidia Fonts". – Elliott Frisch Apr 18 '16 at 16:58
-
`It should stay the same. On any platform.` - you can't control that because you don't know what the default font is on every platform. You should just set the text and let the layout manager do its job. Or the other approach is to create an Icon of the character, then add the Icon to the label. Now the Icon will be consistent on all platforms. – camickr Apr 18 '16 at 17:02
-
@camickr _you don't know what the default font is on every platform_ But the platform on which the applcaition is going to be run does. I thought it would be possible to defne it in apltform independent-way and swing can do this out-of-a-box. – user3663882 Apr 18 '16 at 17:05
-
3It does do it in a platform independent way. You set the text and use a layout manager. – camickr Apr 18 '16 at 17:06
-
`label.setText("1")` then add it to container with an appropriate layout manager, maybe like `GridBagLayout`, see [Laying Out Components Within a Container](http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html) for more details – MadProgrammer Apr 18 '16 at 19:53
-
This [example](http://stackoverflow.com/a/4151403/230513) shows an approach for `JButton`. – trashgod Apr 19 '16 at 02:54