2

What's the Java Swing counterpart for the JavaScript alert() popup (if there is one)?

Bluefire
  • 13,519
  • 24
  • 74
  • 118

3 Answers3

7

An basic way to accomplish such a popup is to use JOptionPane.showMessageDialog, see here.

JOptionPane.showMessageDialog(frame, "here comes the text.");   
// assumes frame to be a reference to the desired parent frame
Howard
  • 38,639
  • 9
  • 64
  • 83
  • How would I make that pane pop up (e.g. when a button is clicked, what code do I use to handle the event?)? – Bluefire Jun 16 '12 at 17:36
  • 1
    @Bluefire You may attach an `ActionListener` to your `JButton`, [see here](http://docs.oracle.com/javase/tutorial/uiswing/components/button.html). – Howard Jun 16 '12 at 17:44
2

Think you are looking for JOptionPanes but here is a good description of the different dialogs: http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html

barsju
  • 4,408
  • 1
  • 19
  • 24
2

How to create a dialog box in Java:

Community
  • 1
  • 1
Christopher Peisert
  • 21,862
  • 3
  • 86
  • 117