开发者

How to create a Jlabel inside JTextArea like in Facebook?

开发者 https://www.devze.com 2023-02-20 23:34 出处:网络
Is there a way I can create a JTextArea or JTextField with some JLabels inside it, like in this screenshot from Facebook:

Is there a way I can create a JTextArea or JTextField with some JLabels inside it, like in this screenshot from Facebook:

How to create a Jlabel inside JTextArea like in Facebook?

What I am trying to do is put some JButtons with titles like "Apple", "Orange", ... When user clicks on a JButton of those, sa开发者_如何学Pythony "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 JLabels to the left (e.g. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号