简体   繁体   English

如何像在Facebook一样在JTextArea中创建Jlabel?

[英]How to create a Jlabel inside JTextArea like in Facebook?

Is there a way I can create a JTextArea or JTextField with some JLabels inside it, like in this screenshot from Facebook: 有没有一种方法可以创建一个内部带有一些JLabel的JTextArea或JTextField,如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. 我要尝试做的是放置一些标题为“ Apple”,“ Orange”,...的JButton。...当用户单击其中的JButton(例如“ Orange”)时,将在单词JTextArea中添加单词Orange的Jlabel。或JTextField。 If user clicked on the [x] on the Jlabel, the word will be removed from the field. 如果用户单击Jlabel上的[x],则该单词将从字段中删除。

I would solve this in a different way: create a JPanel with the border you see. 我将以另一种方式解决此问题:使用您看到的边框创建一个JPanel Add a JTextField without any borders into it, and simply insert your JLabel s to the left (eg using BorderLayout in combination with FlowLayout ). 添加一个没有任何边界的JTextField ,只需将JLabel插入到左侧(例如,结合使用BorderLayoutFlowLayout )。 With a little tweaking of borders and spacings you should be able to create a very similar appearance without having to create new components. 略微调整边框和间距,您应该能够创建非常相似的外观,而无需创建新组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM