0

Hello I've problem in reloading JDialog. I've 2 JRadioButton:

  • Not defined
  • Defined in first row

When I click a button, a dialog will appear, it's content will depend on the radio button. If I choose the first one it will display "Hello World!", but if I choose the second will display "Hello Community!". But the dialog won't change, just display the content based on what I choose first.

Here is my button action:

txtResult.setText(radioOption.getSelectedItem().toString());
JDialog jd = new JDialog();
jd.setSize(600,400); 
jd.setVisible(true);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Fahmi Ramadhan
  • 287
  • 2
  • 4
  • 11

3 Answers3

2

Try this:

JOptionPane.showMessageDialog(frame, radioOption.getSelectedItem().toString());

In above code frame is owner window

EDIT :

And in your code as you have commented txtResult is JTextField so the radioOption text will display on JTextField not on any dialogbox

Harmeet Singh
  • 2,555
  • 18
  • 21
1

There is documentation and I suggest you (not just you) try to read before write any code, Link to examples first line your example, link to doc

Sergii Zagriichuk
  • 5,389
  • 5
  • 28
  • 45
0

Try putting jd.dispose(); at the end of your code. This will remove the message object.

Narayan
  • 68
  • 1
  • 7