java swing display search result in a popup under JTextField “like facebook search”

爷,独闯天下 提交于 2019-12-10 10:59:45

问题


I'm trying to simulate in java swing the same search results preview on facebook, but in java I suppose it'll gonna be :

  • JTextField : the user input goes here
  • JList : containing JList of JPanels ( results )
  • a popup or some container to hold the JList

The problem is, I couldn't manage how to display a popup right under the JTextField, I tried swingx autocomplete, editable combo box , glazedlists ... but it's not giving me good results

Can anyone help me please ?


回答1:


When specifying the point of the popup, pre-calculate (hardcode) or dynamically calculate the location of the bottom left corner of the text field. Use that value or that value plus a few pixels lower as your location for your popup.




回答2:


Without knowing more about the requirements, I'd suggest looking into JWindow




回答3:


I was so pissed of to not be able to find a pre-made class or a .jar that can do what I wanted, so I made my own, in fact I used JWindow, and I made my own Drop Down JTextField menu that extends JTextField ! easy to use : vertical list of JPanels with the same width as the JTextField is drawn and refreshed to display suggestions each time the user enter a new character in the JTextField, then the user can choose ( or not ) between these suggestion by keyboard arrow keys UP and DOWN or by a mouse click ... and we can simply specify if we want to use a document filter for filtering the user's input ( like we wanna just get numerical values in JTextField ) ... and so many other stuff : it rocks !

I'll gladly share this class on the net, I just need some time to write some tutos and examples, but for now, here's two screenshots of what I made one uses Gradient color in a JPanel, and the other one uses the default background color,( don't mind the French JLabels )



来源:https://stackoverflow.com/questions/5460911/java-swing-display-search-result-in-a-popup-under-jtextfield-like-facebook-sear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!