I found this on the Internet, it works really well.
Code:
public class OptionPaneMultiple extends JFrame
{
	public OptionPaneMultiple()
	{
		JTextField firstName = new JTextField();
		JTextField lastName = new JPasswordField();
		Object[] msg = {"First Name:", firstName, "Last Name:", lastName};
 
		JOptionPane op = new JOptionPane(
			msg,
			JOptionPane.QUESTION_MESSAGE,
			JOptionPane.OK_CANCEL_OPTION,
			null,
			null);
 
		JDialog dialog = op.createDialog(this, "Enter Name...");
		dialog.setVisible(true);
 
		int result = JOptionPane.OK_OPTION;
 
		try
		{
		    result = ((Integer)op.getValue()).intValue();
		}
		catch(Exception uninitializedValue)
		{}
 
		if(result == JOptionPane.OK_OPTION)
		{
			System.out.println(firstName.getText() + " : " + lastName.getText());
		}
		else
		{
			System.out.println("Canceled");
		}
 
	}
 
 
	public static void main(String[] args)
	{
		JFrame frame = new OptionPaneMultiple();
		frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
		frame.setAlwaysOnTop(true);
		frame.pack();
		frame.setVisible(true);
	}
}