Reputation: 169
I created this popup window which will show up in response to a button being clicked in my gui. I have two questions regarding this.
My code:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
if(evt.getSource() == jButton2)
optionPopup();
}
private void optionPopup(){
JPanel panel = new JPanel();
JRadioButton undergraduateButton = new JRadioButton();
JRadioButton graduateButton = new JRadioButton();
ButtonGroup group = new ButtonGroup();
undergraduateButton.setText("Option A");
graduateButton.setText("Option B");
group.add(undergraduateButton);
group.add(graduateButton);
panel.add(undergraduateButton);
panel.add(graduateButton);
JOptionPane.showInputDialog(panel);
Upvotes: 0
Views: 920
Reputation: 124215
Use JOptionPane.showMessageDialog
instead of JOptionPane.showInputDialog
if you still want to have ?
icon instead of !
one, use
JOptionPane.showMessageDialog(null, panel, "title", JOptionPane.QUESTION_MESSAGE);
you can also remove icon by using JOptionPane.PLAIN_MESSAGE
If you want to make sure that client pressed OK button use
int response = JOptionPane.showConfirmDialog(null, panel, "title", JOptionPane.PLAIN_MESSAGE);
If response
will be -1
it means window was closed by X
button, if it was 0
user pressed OK
.
More info at: https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
undergraduateButton.isSelected()
and graduateButton.isSelected()
to see if one of them was selected. Upvotes: 5
Reputation: 11020
I think what you're trying to do is referred to as Direct Use of the JOptionPane. Refer to the documentation for more details.
JOptionPane pane = new JOptionPane(arguments);
pane.set.Xxxx(...); // Configure
JDialog dialog = pane.createDialog(parentComponent, title);
dialog.show();
Upvotes: 2