Java Utililty Methods JOptionPane Message

List of utility methods to do JOptionPane Message

Description

The list of methods to do JOptionPane Message are organized into topic(s).

Method

voidalert(Component component, String title, String msg)
alert
JOptionPane.showMessageDialog(component, msg, title, JOptionPane.ERROR_MESSAGE);
StringaskPassword(String message)
ask Password
JLabel wLabel = new JLabel(message);
final JPasswordField wPwd = new JPasswordField();
JOptionPane jop = new JOptionPane(new Object[] { wLabel, wPwd }, JOptionPane.QUESTION_MESSAGE,
        JOptionPane.OK_CANCEL_OPTION);
JDialog dialog = jop.createDialog(null, "Password");
dialog.addComponentListener(new ComponentAdapter() {
    @Override
    public void componentShown(ComponentEvent e) {
...
voidbrowse(String url, Component msgParent)
Opens the given website in the default browser, or shows a message saying that no default browser could be accessed.
boolean error = false;
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
    try {
        Desktop.getDesktop().browse(new URI(url));
    } catch (URISyntaxException ex) {
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        error = true;
...
voidbrowse(String url, Component msgParent)
Opens the given website in the default browser, or shows a message saying that no default browser could be accessed.
boolean error = false;
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) {
    try {
        Desktop.getDesktop().browse(new URI(url));
    } catch (URISyntaxException ex) {
        throw new RuntimeException(ex);
    } catch (IOException ex) {
        error = true;
...
intchooseIndex(String message, String messageTitle, Object[] objects, Object initialObject)
Asks the User to select an Object from a given array of Objects.
Object input = JOptionPane.showInputDialog(null, message, messageTitle, JOptionPane.INFORMATION_MESSAGE,
        null, objects, initialObject);
if (input == null)
    throw new Exception("Selection aborted");
int index = -1;
for (int i = 0; i < objects.length; i++) {
    if (objects[i].equals(input))
        index = i;
...
ObjectchooseObject(String message, String messageTitle, Object[] objects, Object initialObject)
Asks the User to select an Object from a given array of Objects.
Object input = JOptionPane.showInputDialog(null, message, messageTitle, JOptionPane.INFORMATION_MESSAGE,
        null, objects, initialObject);
if (input == null)
    throw new Exception("Selection aborted");
return input;
voidcopyToClipBoard(String code, boolean displayMessage)
copy To Clip Board
java.awt.datatransfer.StringSelection selection = new java.awt.datatransfer.StringSelection(code);
java.awt.Frame frame = new java.awt.Frame();
frame.getToolkit().getSystemClipboard().setContents(selection, selection);
if (displayMessage) {
    JOptionPane.showMessageDialog(null, "Code copied to Clipboard", "Finished",
            JOptionPane.INFORMATION_MESSAGE);
frame.dispose();
...
voidcreatePane(Component comp, String msg)
create Pane
JOptionPane pane = new JOptionPane(msg);
final JDialog dialog = pane.createDialog(comp, "INFORMATION");
Timer timer = new Timer(4000, new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
        dialog.dispose();
});
timer.setRepeats(false);
...
JOptionPanecreatePane(int type, String message, int messageMaxLength)
create Pane
JOptionPane pane = createMaxLengthOptionPane(messageMaxLength);
pane.setMessageType(type);
pane.setMessage(message);
return pane;
voiddebug(String message)
Utility method that can be used to display a debug message.
JOptionPane.showMessageDialog(null, message);