Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display layer below JComboBox

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have an implementation of searchable JComboBox that extends from JComboBox. Right now the combo box only searches for the first occurance of matched string, I want to get the whole set of matches. The logic stuff works, but how does GUI? I am thinking of putting found data in JList and making it visible, but should I put JList in the frame and make frame visible when action listener is fired? If yes, how can I calculate so that JList appears directly below JComboBox? Can I use JComboBox's own JList (the one that appears when user wants to see contents of JComboBox) as my temporary component for found matches?
Also, is there a way to display JFrame without any titles or status bars?

thanks a lot,
Alex
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should I put JList in the frame
You could. You might also consider using a JDialog, JOptionPane or a JPopupMenu.

is there a way to display JFrame without any titles or status bars
Look in the JFrame api, scroll down below the Method Summary section to Methods inherited from class java.awt.Frame for the setUndecorated method. Follow the link to see what it does.

how can I calculate so that JList appears directly below JComboBox?
see Methods inherited from class java.awt.Component in JFrame api


Can I use JComboBox's own JList (the one that appears when user wants to see contents of JComboBox) as my temporary component for found matches?
Possibly, depends on what you want to do.
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Excellent!
I looked in JComboBox API and there are couple of methods there that come really handy to what I am doing: showPopup() and hidePopup() these two bring up and hide the actual JComboBox's list. So I use this list to populate my results when JComboBox is being searched, and populate it back with all items when something was selected from the matches. Works really nice. The only thing that might be a problem is that I populate JComboBox with adding each item in a for loop, when JComboBox will have a lot of items, looping might take some time to finish, I think I will use ComboBoxModel to setModel of the combo box. Otherwise works like a charm.

thanks,
Alex
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic