Forums Register Login

labels in java gui components

+Pie Number of slices to send: Send
hi all.
Is there good coding practice for putting labels in java gui controls? If I'm coding a java gui application, is it ok to hard code the labels...like for example...
Button b = new Button("Ok");
thanks.
+Pie Number of slices to send: Send
hey Dennis,
Thats what i do,
here is a piec of code i did for my distance learning course:

Davy
+Pie Number of slices to send: Send
sorry bearing in mind that the above posted code is a constructor, with these member variables:

Davy
+Pie Number of slices to send: Send
There is nothing wrong with that, especially if you know you will not have to internationalize the application. If so, you may want to put the message Strings in a resource bundle and pull them out as needed in the app. It's also worth noting that some IDE's, like NetBeans, provide some support for helping to do this internationalization after the fact.
+Pie Number of slices to send: Send
Hi Davy,Ken...looks good. Thank you for your replies.
+Pie Number of slices to send: Send
Having written 2 applications that are available to the world, I now put all Strings into a ResourceBundle from the start of a project. This helps in two ways:
1) If you ever i18n, the work is already done for you.
2) As I write the app, I tend to change the strings displayed to the user fairly often til I get it right. By having all the strings in one place, I don't have to hunt down which class the String is defined in and I can change a string without recompiling.
Just my $0.02
Brian
+Pie Number of slices to send: Send
Moving this to Swing/AWT.
+Pie Number of slices to send: Send
Hi Brian. Thanks for your reply. Seems like a good idea but is there a performance-related issue with your approach?
thanks.
+Pie Number of slices to send: Send
Most of the time a label on a component is set one time (at creation time) and a lookup of the string for it in a ResourceBundle will take negligible time compared to setting up the rest of the Swing/SWT/GUI. So, no there should not be a noticeable performance hit. Even if you change the label after it's created, a simple lookup of the string does not make any noticeable difference in the GUI. Download and try either of my apps (links in sig) - both are i18n'd - every piece of text you see is stored in a ResourceBundle (a .properties file) which is stored in the program's .jar file.
Brian
[ February 10, 2004: Message edited by: Brian Pipa ]
+Pie Number of slices to send: Send
Awesome. Thanks Brian.
My cellmate was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1532 times.
Similar Threads
Hard coding component size in GUI?
Head First Java -- Need Help!
dynamically change gui components attributes
swing(gui) code - how to keep it organized?
Which one is better for creating GUI using swings?? Manual coding or IDE drag and drop???
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:43:36.