想要在 JTextArea 上显示 JList
我想在 JTextArea 上显示 JList,但它显示在 JTextArea 后面。我附上了两张图片来通过图像来描述我的问题。在运行时我们如何在 JTextArea 上设置 JList?
JTextArea 后面的 JList:
JTextArea 上的 JList:
I want to disply JList over the JTextArea but its showing it behind the JTextArea. I have attached two images to describe my problem through images.At runtime how can we set JList over the JTextArea?
JList behind JTextArea:
JList over JTextArea:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
bsm:在这种情况下,您不应该使用 JList,而应该使用 JComboBoxes,它的下拉列表可以在 JTextArea 上正确显示。例如,
我还重新建议您暂时将 NetBeans 代码生成放在一边,因为我真诚地相信,对于许多人来说,这会阻碍他们学习如何在 Swing 中进行编码的能力。
bsm: you should not use JLists for this situation but JComboBoxes which will have drop down lists that display correctly over the JTextArea. For e.g.,
I also re-recommend that you put your NetBeans code generation to the side for the time being as I honestly believe that for many it hinders their ability to learn how to code in Swing.
我认为默认行为是在其他组件上显示组合内容,因此您可以这样。我目前想到的唯一建议是使用分层窗格。
您可以检查带有选项的组合框部分添加到哪一层。然后将该列表添加到上面的列表中。
关于 LayeredPane 的教程 http://download.oracle.com/javase/tutorial/ uiswing/components/layeredpane.html
从 RootPane 的描述中我认为组合框的选项必须显示在弹出层上 http://download.oracle.com/javase/tutorial/uiswing/components/rootpane.html
祝你好运,Boro。
I would think that default behaviour is to show combo content over other components, thus you have it this way. The only suggestion that I would think of at the moment is to use layered pane.
You could check to which layer the part of combo box with options is added. Then add the list to one above.
Tutorial about LayeredPane http://download.oracle.com/javase/tutorial/uiswing/components/layeredpane.html
From this description of RootPane I think the options of combobox must be shown on popup layer http://download.oracle.com/javase/tutorial/uiswing/components/rootpane.html
Good luck, Boro.