JList selected item to String

后端 未结 4 2267
清酒与你
清酒与你 2021-02-19 15:10

Could someone tell me how to get the selected item of JList to a String? It is a single selection JList.

4条回答
  •  感情败类
    2021-02-19 15:43

    private void jList1MouseClicked(java.awt.event.MouseEvent evt) {
    
        Object sel =null;
    
        int[] selectedIx = this.jList1.getSelectedIndices();      
    
        for (int i = 0; i < selectedIx.length; i++) {
            sel = jList1.getModel().getElementAt(selectedIx[i]);
        }
    
        System.out.println(sel);
    }
    

提交回复
热议问题