Forgive me if this question is trivial. I am not a GUI expert. However, i need to create a Swing control in which the text will only be inserted programmatically based on some calculation (user input never allowed). Are there any preferences here to use JLabel vs. noneditable JTextField? I understand that both will work, but just curious if it is better to use one or another in such circumstances.
Asked
Active
Viewed 4,464 times
2
-
4A `JTextField` can be focused, the user can select the text and copy it if need be. If there *ever* would be a need for the user to transfer that information into another app. or record it etc., I would choose the text area/field. Of course, if you implement D'n'D for the data item, the need for copy/paste is diminished. – Andrew Thompson May 21 '15 at 19:20
-
I apologize, JTextField – tulu May 21 '15 at 19:21
-
@Andrew, thank you for answering my question. Yes, C&P is good functionality, so JTextField it is. And, btw, what is D'n'D? – tulu May 21 '15 at 19:23
-
1The JLabel can handle ImageIcons *much* better than a JTextField. – Hovercraft Full Of Eels May 21 '15 at 19:25
-
2JLabel supports some basic html tags, which can be handy to add some styling. – Dragan Bozanovic May 21 '15 at 19:31
2 Answers
6
The difference is how they look and behave. Also you can cut(&paste) from JTextField.
-
1See also [How to create great screenshots?](http://meta.stackexchange.com/q/99734/155831) (I'm thinking specifically **'alt** + Print Screen' here to crop the size to the active window.) – Andrew Thompson May 21 '15 at 19:36