How to create a search bar similar to Google search style in JAVA GUI

前端 未结 1 783
攒了一身酷
攒了一身酷 2020-12-19 18:19

I am trying to create a search feature in my program similar to google search bar, where when user is typing it actually searches the database and displays the current resul

相关标签:
1条回答
  • 2020-12-19 18:46

    SwingX API would helpful to solve this issue. You can use the following code to implement auto complete feature to editable ComboBox.

    import javax.swing.*;
    import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
    import java.awt.*;
    public class Demo {
    
        JFrame frame = new JFrame("");
        AutoCompleteDecorator decorator;
        JComboBox combobox;
    
        public Demo() {
            combobox = new JComboBox(new Object[]{"","Ester", "Jordi",
                "Jordina", "Jorge", "Sergi"});
            AutoCompleteDecorator.decorate(combobox);
            frame.setSize(400,400);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new FlowLayout());
    
            frame.add(combobox);
            frame.setVisible(true);
        }
    
        public static void main(String[] args) {
            Demo d = new Demo();
        }
    }
    
    0 讨论(0)
提交回复
热议问题