Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOptionPane with multiple buttons on each line?

How would I go about displaying a JOptionPane.showinputDialog() with multiple JButtons on each line? I am not talking about the Yes, No, Cancel buttons but multiple custom labeled JButtons that displays in the content area of JOptionPane.showinputDialog?

so I would need to get the value of the button pressed from the JOptionPane as well.

like image 760
KJW Avatar asked Dec 28 '11 16:12

KJW


1 Answers

You can place any JComponents to the JOptionPane, there I can't see any limits, JOptionPane is same Top-Level Container as JFrame, JDialog or JWindow, but in contrast with plain Top-Level Containers, JOptionPane has implemented return events from built-in funcionalities in Integer value, meaning buttons YES, NO, OK, CANCEL and CLOSE too,

put all JButtons to the Array

String[] buttons = { "Yes", "Yes to all", "No", "Cancel".... };    
int returnValue = JOptionPane.showOptionDialog(null, "Narrative", "Narrative",
        JOptionPane.WARNING_MESSAGE, 0, null, buttons, buttons[i]);
System.out.println(returnValue);
like image 124
mKorbel Avatar answered Oct 03 '22 21:10

mKorbel