2

そのアイテムをjlistに追加した後、オートコンプリートコンボボックスからアイテムを削除します

ここで、 glazedlists_java15-1.9.0.jarという名前の jar ファイルを追加します

これはjpanelにフィールドを追加するためのコードです

            DefaultComboBoxModel dt=new DefaultComboBoxModel();
       comboBook = new JComboBox(dt);         
       comboBook.addItemListener(this);
       List<Book>books=ServiceFactory.getBookServiceImpl().findAllBook();
       Object[] elementBook = new Object[books.size()];         
        int i=0;
        for(Book b:books){
            elementBook[i]=b.getCallNo();
        //   dt.addElement(elementBook[i]);
            i++;
        }

        AutoCompleteSupport.install(comboBook, GlazedLists.eventListOf(elementBook));
        comboBook.setBounds(232, 151, 184, 22);
        issuePanel.add(comboBook);

        btnAdd = new JButton("+");
        btnAdd.addActionListener(this);
        btnAdd.setBounds(427, 151, 56, 23);
        issuePanel.add(btnAdd);

        JScrollPane scrollPane = new JScrollPane();
        scrollPane.setBounds(232, 184, 184, 107);
        issuePanel.add(scrollPane);


        v=new Vector<String>();
        listBooks = new JList(v);
        scrollPane.setViewportView(listBooks);

         btnRemove = new JButton("-");
         btnRemove.addActionListener(this);
        btnRemove.setBounds(427, 185, 56, 23);
        issuePanel.add(btnRemove);

アクション実行コードはこちら..

 public void actionPerformed(ActionEvent e) {

    if(e.getSource()==btnAdd){

        DefaultComboBoxModel dcm = (DefaultComboBoxModel) comboBook.getModel();
        dcm.removeElementAt(index);
        // Add what the user types in JTextField jf, to the vector
          v.add(selectedBook);

          // Now set the updated vector to JList jl
          listBooks.setListData(v);

          // Make the button disabled
          jb.setEnabled(false);

    }
    else if(e.getSource()==btnRemove){
         // Remove the selected item
           v.remove(listBooks.getSelectedValue());

           // Now set the updated vector (updated items)
           listBooks.setListData(v);

    }

ここに画像の説明を入力

この画像は、コンボボックスからjlistにアイテムを追加し、コンボボックスからアイテムを非表示または削除することを示しています。

あなたがこれについて知っているなら、ここで答えを共有してください..&ありがとう!!!

4

1 に答える 1