Is there a way I can create a JTextArea or JTextField with some JLabels inside it, like in this screenshot from Facebook:
What I am trying to do is put some JButtons with titles like "Apple", "Orange", ... When user clicks on a JButton of those, say "Orange", a Jlabel with the word Orange will be added to the JTextArea or JTextField. If user clicked on the [x] on the Jlabel, the word will be removed from the field.
I would solve this in a different way: create a JPanel
with the border you see. Add a JTextField
without any borders into it, and simply insert your JLabel
s to the left (eg using BorderLayout
in combination with FlowLayout
). With a little tweaking of borders and spacings you should be able to create a very similar appearance without having to create new components.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.