0

私のアプリケーションでは、ユーザーが名、姓、および電話番号を入力できるようにしています。ユーザーが追加ボタンをクリックすると、エントリが jlist に追加されます (電話帳のように)。JListの上にjTextfieldがあり、ユーザーがJlistで特定の名前または電話番号を検索できるようにしたいので、文字を入力するGoogle検索のようなもので、JListに関連する文字を含む名前が表示され、そのような。この時点で本当に立ち往生して迷っています。

これは、Jlist に名前を追加するための追加ボタン コードです。

private void btnAddContactActionPerformed(java.awt.event.ActionEvent evt) {

    String firstName = txtFirstName.getText();
    String lastName = txtLastName.getText();
    String phoneNum = (txtPhoneNum.getText());
    NumberFormat number = NumberFormat.getNumberInstance();
    //Phone Number formatted
   StringBuilder sb = new StringBuilder(phoneNum).insert(0, "(")
           .insert(4,")").insert(8,"-");
   String phoneNumFormatted = sb.toString();

    contactsArrayList.add(firstName + "\t    " + lastName + "\t    " + phoneNumFormatted);
    DefaultListModel<String> model = new DefaultListModel<>();
    for(int i = 0; i < contactsArrayList.size(); i++)
    {
        String myArraylst = contactsArrayList.get(i);
        model.addElement(myArraylst + "\t");
    }

    listPhoneBookContacts.setModel(model);
    txtFirstName.setText("");
    txtLastName.setText("");
    txtPhoneNum.setText("");

}
4

2 に答える 2

0

It is possible to implement this kind of stuff in Swing, but it is gnarly and you are unlikely to do a good job of it (because it's hard). You're probably better off leaving it to some other library, like SwingX. They have a bunch of components you can use that might do exactly what you want.

If you don't want to use that, a quick Google search reveals a good tutorial for filtering JLists.

于 2013-04-28T04:15:48.293 に答える