Joption acting like it's in a for loop

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4

46 Replies - 1698 Views - Last Post: 04 February 2018 - 10:37 AM Rate Topic: -----

#46 Piet Souris  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 176
  • Joined: 01-December 15

Re: Joption acting like it's in a for loop

Posted 31 January 2018 - 04:23 PM

I hope I understood it correctly:

when you receive an Enter in the OptionPane, use this code:
if (input == JOptionPane.OK_OPTION) {

    System.out.println("ok");
    l_names.clearSelection();
    tf_search.setText("");
    // and restore the contents of the JList, so that the user sees the full list again
    tf_search.requestFocus();

}

Why do you add a KeyListener to the JList only after an Enter in the JTextField? Why not have a permanent listener, so that the JList also works independently from the TextField?

This post has been edited by Piet Souris: 31 January 2018 - 04:24 PM

Was This Post Helpful? 0
  • +
  • -

#47 ViSion91  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 112
  • Joined: 26-March 17

Re: Joption acting like it's in a for loop

Posted 04 February 2018 - 10:37 AM

I made it permanent in the last code i shared and everything work great thanks for the help .
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • « First
  • 2
  • 3
  • 4