I have an arraylist with objects and a running Gui. I looking for a way to popup a little frame or box or something like that which displays the objects from the arraylist. The user now should be able to choose one or more items which are then returned.
I have already the optionpane but i can just select one object
Object[] possibilities = lr.declarationList.toArray();
String s = (String)JOptionPane.showInputDialog(
gui.getFrame(),
"Choose Target Nodes",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
null);
maybe a popup list would help out.
The JOptionPane displays the dialog boxes with one of the four standard icons (question, information, warning, and error) or the custom icons specified by the user.
JOptionPane. showInputDialog() will return the string the user has entered if the user hits ok, and returns null otherwise. Therefore, you can just check to see if the resultant string is null .
We call the static showMessageDialog() method of the JOptionPane class to create a message dialog. We provide the dialog's parent, message text, title, and message type. The message type is one of the following constants : ERROR_MESSAGE. WARNING_MESSAGE.
Try using JOptionPane.showMessageDialog(...)
with a JList component argument whose elements are sourced from your list, for example:
JList list = new JList(new String[] {"foo", "bar", "gah"});
JOptionPane.showMessageDialog(
null, list, "Multi-Select Example", JOptionPane.PLAIN_MESSAGE);
System.out.println(Arrays.toString(list.getSelectedIndices()));
Note that if you need more layout items in the message object itself you can pack them all into a JPanel and use that component as the message argument.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With