Java Code Examples for javax.swing.JOptionPane.ERROR_MESSAGE

The following are Jave code examples for showing how to use ERROR_MESSAGE of the javax.swing.JOptionPane class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: student_database   File: AddPanel.java   View Source Code Vote up 7 votes
private void errorDialogue(String messageString, int whichField) {
    Object[] message = {messageString};
    Object[] options = {"OK"};
    int n = JOptionPane.showOptionDialog(new JFrame(),
            message, "Alert!",
            JOptionPane.ERROR_MESSAGE, JOptionPane.ERROR_MESSAGE, null,
            options, options[0]);
    if(JOptionPane.ERROR_MESSAGE == n && whichField == 0){
        this.addStudentFullName.setText("");
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 1){
        this.addStudentID.setText("171-15-XXXX");
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 2){
        this.addFathersNameField.setText("");
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 3){
        this.addMothersNameField.setText("");
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 4){
        displayUpdateStudentPanel(true, false);
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 5){
        panelVisiblity(true, false, false, false);
    } else if(n == JOptionPane.ERROR_MESSAGE && whichField == 6){
        loginVisiblity(true, false);
    } else {
        //DO NOTHING JUST DISPLAY MESSAGE
    }
}
 
Example 2
Project: Java-RPG-Maker-MV-Decrypter   File: NotificationWindow.java   View Source Code Vote up 6 votes
/**
 * Returns the JOptionPane Type depending on the Error-Level
 *
 * @return - JOptionPane Type
 */
protected int getJOptionType() {
	switch(this.errorLevel) {
		case ERROR_LEVEL_NOTICE:
			return JOptionPane.INFORMATION_MESSAGE;
		case ERROR_LEVEL_WARNING:
			return JOptionPane.WARNING_MESSAGE;
		case ERROR_LEVEL_ERROR:
			return JOptionPane.ERROR_MESSAGE;
		case ERROR_LEVEL_FATAL:
			return JOptionPane.ERROR_MESSAGE;
		case ERROR_LEVEL_INFO:
		default:
			return JOptionPane.INFORMATION_MESSAGE;
	}
}
 
Example 3
Project: AWGW   File: WorldFrame.java   View Source Code Vote up 6 votes
public void handle(Throwable e) {
    e.printStackTrace();

    JTextArea area = new JTextArea(10, 40);
    StringWriter writer = new StringWriter();
    e.printStackTrace(new PrintWriter(writer));
    area.setText(writer.toString());
    area.setCaretPosition(0);
    String copyOption = resources.getString("dialog.error.copy");
    JOptionPane pane = new JOptionPane(new JScrollPane(area), JOptionPane.ERROR_MESSAGE,
            JOptionPane.YES_NO_OPTION, null, new String[]{copyOption, resources.getString("cancel")});
    pane.createDialog(WorldFrame.this, e.toString()).setVisible(true);
    if (copyOption.equals(pane.getValue())) {
        area.setSelectionStart(0);
        area.setSelectionEnd(area.getText().length());
        area.copy(); // copy to clipboard
    }
}
 
Example 4
Project: Equella   File: ProgressWindow.java   View Source Code Vote up 5 votes
@Override
public void popupMessage(String title, String message, boolean error)
{
	int type = JOptionPane.INFORMATION_MESSAGE;
	if( error )
	{
		type = JOptionPane.ERROR_MESSAGE;
	}

	JOptionPane.showMessageDialog(this, message, title, type);
}
 
Example 5
Project: scorekeeperfrontend   File: AppSetup.java   View Source Code Vote up 5 votes
public void publish(LogRecord logRecord)
{
    if (isLoggable(logRecord))
    {
        int type;
        String title;
        if (logRecord.getMessage().charAt(0) != '\b') {
            return;
        }

        int val = logRecord.getLevel().intValue();
        if (val >= Level.SEVERE.intValue())
        {
            title = "Error";
            type = JOptionPane.ERROR_MESSAGE;
        }
        else if (val >= Level.WARNING.intValue())
        {
            title = "Warning";
            type = JOptionPane.WARNING_MESSAGE;
        }
        else
        {
            title = "Note";
            type = JOptionPane.INFORMATION_MESSAGE;
        }

        String record = getFormatter().formatMessage(logRecord).replaceAll("[\b]","");
        if (record.contains("\n"))
            record = "<HTML>" + record.replace("\n", "<br>") + "</HTML>";

        // stay off FX or other problem threads
        final String msg = record;
        SwingUtilities.invokeLater(new Runnable() {
            @Override public void run() {
                JOptionPane.showMessageDialog(FocusManager.getCurrentManager().getActiveWindow(), msg, title, type);
            }
        });
    }
}
 
Example 6
Project: incubator-netbeans   File: UiUtils.java   View Source Code Vote up 4 votes
public static boolean showMessageDialog(
        final String message,
        final String title,
        final MessageType messageType) {
    initLAF();
    
    boolean exitInstaller = false;
    
    switch (UiMode.getCurrentUiMode()) {
        case SWING:
            int intMessageType = JOptionPane.INFORMATION_MESSAGE;                               
            
            LogManager.logIndent("... show message dialog");
            LogManager.log("title: "+ title);
            LogManager.log("message: " + message);
            
            if (messageType == MessageType.WARNING) {
                intMessageType = JOptionPane.WARNING_MESSAGE;                
            } else if (messageType == MessageType.CRITICAL) {
                intMessageType = JOptionPane.ERROR_MESSAGE;
                exitInstaller = true;
            }
            
            if (messageType == MessageType.ERROR) {                    
                int result = JOptionPane.showOptionDialog(null,
                                    message,
                                    title,
                                    JOptionPane.YES_NO_OPTION,
                                    JOptionPane.ERROR_MESSAGE,
                                    null,
                                    null,
                                    JOptionPane.YES_OPTION);
                if (result == JOptionPane.NO_OPTION) {
                    exitInstaller = true;
                    LogManager.logUnindent("... user selected: NO");                        
                } else {
                    LogManager.logUnindent("... user selected: YES");
                }
            } else {
                JOptionPane.showMessageDialog(null, 
                        message, 
                        title, 
                        intMessageType);
            }
            
            LogManager.logUnindent("... dialog closed");
            break;
        case SILENT:
            LogManager.log(message);
            System.err.println(message);
            break;
    }
    
    return exitInstaller;
}
 
Example 7
Project: JavaGraph   File: ErrorDialog.java   View Source Code Vote up 4 votes
/**
 * Constructs a new error dialog, with the same top-level frame as the given
 * component, a simple error message, and an exception giving more detail
 * about the error. The dialog is not yet shown.
 */
public ErrorDialog(Component component, String message, Throwable exc) {
    super(getParentFrame(component), ERROR_MESSAGE_TEXT, true);
    setLocationRelativeTo(component);
    this.exc = exc;

    // setup cancel button
    JComponent cancelPane = Box.createHorizontalBox();
    this.cancelButton = new JButton(CANCEL_BUTTON_TEXT);
    cancelPane.add(Box.createHorizontalGlue());
    cancelPane.add(this.cancelButton);
    cancelPane.add(Box.createHorizontalGlue());
    this.cancelButton.setSelected(true);

    // setup details pane
    this.detailsButton = new JButton(NO_DETAILS_BUTTON_TEXT);
    this.detailsButton.setEnabled(exc != null);
    JComponent detailsButtonPane = Box.createHorizontalBox();
    detailsButtonPane.add(this.cancelButton);
    detailsButtonPane.add(Box.createHorizontalGlue());
    detailsButtonPane.add(this.detailsButton);

    this.detailsPane = new JPanel(new BorderLayout());
    this.detailsPane.add(detailsButtonPane, BorderLayout.SOUTH);

    // setup message pane
    JPanel messagePane = new JPanel(new BorderLayout());
    messagePane.setPreferredSize(new Dimension(300, 100));
    messagePane.add(this.detailsPane, BorderLayout.CENTER);

    // setup option pane
    JOptionPane optionPane =
        new JOptionPane(message, JOptionPane.ERROR_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
            new Object[] {messagePane});
    optionPane.add(messagePane, BorderLayout.SOUTH);
    // setup content pane
    Container contentPane = getContentPane();
    contentPane.add(optionPane);
    // constrain size to maximum
    setPreferredSize();

    // setup text area
    this.detailsArea = new JTextArea();
    this.detailsArea.setEditable(false);
    this.detailsTextPane = new JScrollPane(this.detailsArea);
    this.detailsTextPane.setPreferredSize(new Dimension(300, 100));
    this.detailsTextPane.setBorder(new EmptyBorder(5, 0, 5, 0));
    setDetailsLevel(NO_DETAILS);

    // setup button listener
    ActionListener buttonListener = new ButtonListener();
    this.cancelButton.addActionListener(buttonListener);
    this.detailsButton.addActionListener(buttonListener);
    pack();
}
 
Example 8
Project: OpenJSharp   File: DialogCallbackHandler.java   View Source Code Vote up 4 votes
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}
 
Example 9
Project: jdk8u-jdk   File: DialogCallbackHandler.java   View Source Code Vote up 4 votes
void setCallback(ConfirmationCallback callback)
    throws UnsupportedCallbackException
{
    this.callback = callback;

    int confirmationOptionType = callback.getOptionType();
    switch (confirmationOptionType) {
    case ConfirmationCallback.YES_NO_OPTION:
        optionType = JOptionPane.YES_NO_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.NO
        };
        break;
    case ConfirmationCallback.YES_NO_CANCEL_OPTION:
        optionType = JOptionPane.YES_NO_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.YES_OPTION, ConfirmationCallback.YES,
            JOptionPane.NO_OPTION, ConfirmationCallback.NO,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.OK_CANCEL_OPTION:
        optionType = JOptionPane.OK_CANCEL_OPTION;
        translations = new int[] {
            JOptionPane.OK_OPTION, ConfirmationCallback.OK,
            JOptionPane.CANCEL_OPTION, ConfirmationCallback.CANCEL,
            JOptionPane.CLOSED_OPTION, ConfirmationCallback.CANCEL
        };
        break;
    case ConfirmationCallback.UNSPECIFIED_OPTION:
        options = callback.getOptions();
        /*
         * There's no way to know if the default option means
         * to cancel the login, but there isn't a better way
         * to guess this.
         */
        translations = new int[] {
            JOptionPane.CLOSED_OPTION, callback.getDefaultOption()
        };
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized option type: " + confirmationOptionType);
    }

    int confirmationMessageType = callback.getMessageType();
    switch (confirmationMessageType) {
    case ConfirmationCallback.WARNING:
        messageType = JOptionPane.WARNING_MESSAGE;
        break;
    case ConfirmationCallback.ERROR:
        messageType = JOptionPane.ERROR_MESSAGE;
        break;
    case ConfirmationCallback.INFORMATION:
        messageType = JOptionPane.INFORMATION_MESSAGE;
        break;
    default:
        throw new UnsupportedCallbackException(
            callback,
            "Unrecognized message type: " + confirmationMessageType);
    }
}