1

I have to create a searching window, like a google browser window. It must have a pull down list containing similar results, which is populated from a database.

I am trying to adjust a JCombobox but this has caused ​​me a lot of trouble. Is there a better way to do this? (Perhaps something like this already exists in Java.) If not, can anyone advise me on how to achieve my goal?

Leigh
  • 28,765
  • 10
  • 55
  • 103

2 Answers2

2

create JTextField with keyboard event to show the popup window on key realeased, Example:

jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            showPopup(evt);
        }
    });
 void showPopup(java.awt.event.KeyEvent evt) {

       JPopupMenu popup = new JPopupMenu();
        popup.setLightWeightPopupEnabled(false);
        popup.setBorder(BorderFactory.createLineBorder(Color.black));
        popup.setLayout(new BorderLayout());
        popup.setSize(this.getPreferredSize());
        popup.setPreferredSize(this.getPreferredSize());
        popup.pack();
        popup.setOpaque(false);
        // create panel that contains the search result 
        popup.add(BorderLayout.CENTER, <YOUR PANEL WITH THE RESULT>);
        popup.setPreferredSize(new Dimension(jTextField2.getWidth(),250));
        <SEARCH PANEL>.setPreferredSize(new Dimension(jTextField2.getWidth(),250));
        popup.show(jTextField2, 0, jTextField2.getHeight());
      }
Bridge
  • 29,818
  • 9
  • 60
  • 82
1

i have to do searching window like google browser window. It must have pull down list with similarities results that comes from database. I trying to adjust JCombobox but this made ​​me a lot of trouble.

Maybe not true, I'd to use AutoComplete JComboBox / JTextField

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319