Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: POPUP DISPLAY ONLY ONE ITEMS FROM THE DATABASE SQL BUT I NEED ATLEAST FIVE ITEMS TO DISPLAY IN JCOMBOBOX

  1. #1
    Junior Member
    Join Date
    Oct 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default POPUP DISPLAY ONLY ONE ITEMS FROM THE DATABASE SQL BUT I NEED ATLEAST FIVE ITEMS TO DISPLAY IN JCOMBOBOX

    txtfName = new JTextField();
    txtfName.setBorder(null); // <-- this has no effect.
    txtfName.addKeyListener(new KeyAdapter() {
    @SuppressWarnings("unchecked")
    @Override
    public void keyReleased(KeyEvent e) {

    try {
    cboName.removeAllItems();
    cboName.setPopupVisible(true);
    cboName.showPopup();
    String val = txtfName.getText().trim();
    if (!val.equals("")) {
    String query = "select distinct CUSTOMER from TBL_DRUG_123 where CUSTOMER like '%" + val
    + "%' ";
    Statement pst = conn.createStatement();
    ResultSet rs = pst.executeQuery(query);

    while (rs.next()) {
    cboName.addItem(rs.getString("CUSTOMER"));

    }
    }

    } catch (Exception e1) {
    e1.printStackTrace();

    }
    }

    @Override
    public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
    String str = (String) cboName.getSelectedItem();
    txtfName.setText(str);
    }
    }
    });
    txtfName.setBounds(406, 294, 159, 20);
    contentPane.add(txtfName);
    txtfName.setColumns(10);

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: POPUP DISPLAY ONLY ONE ITEMS FROM THE DATABASE SQL BUT I NEED ATLEAST FIVE ITEMS TO DISPLAY IN JCOMBOBOX

    Can you post the program's current output to show what you are talking about? Add some comments describing what is wrong and show what the desired output is. Add some print statements as needed to show the output.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Ordering items but a bit more complex then just swapping items
    By alfa86 in forum Collections and Generics
    Replies: 26
    Last Post: July 13th, 2019, 06:12 PM
  2. Disable items in JComboBox or ?
    By JavaCoderJ in forum Object Oriented Programming
    Replies: 1
    Last Post: October 26th, 2013, 07:58 PM
  3. Replies: 7
    Last Post: February 2nd, 2013, 11:07 AM
  4. JComboBox help again but different help 75+ items in it
    By derekxec in forum AWT / Java Swing
    Replies: 7
    Last Post: August 27th, 2011, 06:53 PM
  5. How do I display 4 items at a time of an ArrayList?
    By JavaStruggler in forum Member Introductions
    Replies: 5
    Last Post: August 9th, 2011, 02:33 PM