I have to find the longest word for each value from JScrollPane, not only a selected one. How do I get all values, without selecting anything?
I have the list defined : list = new JList<String>(model);
btnNewButton_1.addActionListener(new ActionListener() { // Run
public void actionPerformed(ActionEvent e) {
String intxt = "", extxt = "";
intxt = list.getSelectedValue();
if (intxt == null) {
JOptionPane.showMessageDialog(null, "No chosen value", "Error",
JOptionPane.INFORMATION_MESSAGE);
} else {
...
You can use a
for
loop in itsListModel
and callgetElementAt(int index)
method: