Reputation: 1364
I'm trying to achieve something similar to this:
public void execute(){
RandomClass item = showPopupBox(randomClassArrayList).selectItem();
randomClassArrayList.remove(item);//Obv I can make this one line.
}
showPopupBox
would create a popup box (go figure), populate a list of radio buttons for each item on the list, and return a selected item from the list when you pushed the OK button. until then the execute method would wait for the popupbox to return the item from the popup box selected via radio button.
I cant really post anything more than this because if I could I wouldn't need to ask. I'm trying to fill a parameter via popup box.
My question is only related to having the execute()
method wait for the OK button of the popup box to be pressed, which would fill the parameter and finish the execute()
method
Upvotes: 2
Views: 495
Reputation: 117607
You can do something like this (not tested):
public static RandomClass showPopupBox(List<RandomClass> list)
{
JRadioButton[] rdoArray = new JRadioButton[list.size()];
ButtonGroup group = new ButtonGroup();
JPanel rdoPanel = new JPanel();
for(int i = 0; i < list.size(); i++)
{
rdoArray[i] = new JRadioButton(list.get(i).toString());
group.add(rdoArray[i]);
rdoPanel.add(rdoArray[i]);
}
rdoArray[0].setSelected(true);
JOptionPane pane = new JOptionPane();
int option = pane.showOptionDialog(null, rdoPanel, "The Title",
JOptionPane.NO_OPTION,
JOptionPane.PLAIN_MESSAGE,
null, new Object[]{"Submit!"}, null);
if(option == 0)
{
for(int i = 0; i < list.size(); i++)
if(rdoArray[i].isSelected()) return list.get(i);
}
return null;
}
Then, you can use it like this:
RandomClass item = showPopupBox(randomClassArrayList);
Upvotes: 4