Hello correcting a little information of the colleague:
JOptionPane.showMessageDialog(null, //Qualquer Componente nao so Frame
"Usuário ou senha incorreto!", //mensagem para o usuario
"Inane error", //icone de erro pode deixar em branco ou null se não quiser usá-lo
JOptionPane.ERROR_MESSAGE); //tipo de mensagem
A small example of code ,in which, without closing the JOptionPane
it is impossible to click the other components in the Frame.
JFrame frame = new JFrame("teste");
JPanel painel = new JPanel(new GridLayout(2, 2));
JButton button1 = new JButton("01");
JButton button2 = new JButton("02");
JButton button3 = new JButton("03");
JButton button4 = new JButton("04");
button1.addActionListener((ActionEvent e) -> {
JOptionPane.showMessageDialog(button1, e.getActionCommand(),
"Titulo: Mensagem Informação ",JOptionPane.INFORMATION_MESSAGE);
});
button2.addActionListener((ActionEvent e) -> {
JOptionPane.showMessageDialog(button2, e.getActionCommand(),
"Titulo: Mensagem Questão ",JOptionPane.QUESTION_MESSAGE);
});
button3.addActionListener((ActionEvent e) -> {
JOptionPane.showMessageDialog(button3, e.getActionCommand(),
"Titulo: Mensagem Atenção ",JOptionPane.WARNING_MESSAGE);
});
button4.addActionListener((ActionEvent e) -> {
JOptionPane.showMessageDialog(button4, e.getActionCommand(),
"Titulo: Mensagem Erro ",JOptionPane.ERROR_MESSAGE);
});
painel.add(button1);
painel.add(button2);
painel.add(button3);
painel.add(button4);
frame.add(painel);
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Now, maybe you’re after a JDialog
it has an option called AlwaysOnTop
which, when true, keeps the same always in front of any window regardless of which select. It can also be used to Replace a Jframe.
JFrame frame = new JFrame("teste");
JPanel painel = new JPanel(new GridLayout(2, 1));
JButton button1 = new JButton("01");
JButton button2 = new JButton("02");
button1.addActionListener((ActionEvent e) -> {
JDialog dialog = new JDialog();
dialog.setSize(200, 200);
dialog.add(new JLabel("JDialog Teste"));
dialog.setAlwaysOnTop(true);//Fica sobre todas as janelas
dialog.setModal(true);//Impede que seja as janelas em segundo plano sejam acessadas
dialog.setVisible(true);
});
button2.addActionListener((ActionEvent e) -> {
JOptionPane.showMessageDialog(button2, e.getActionCommand(),
"Titulo: Mensagem Erro ",JOptionPane.ERROR_MESSAGE);
});
painel.add(button1);
painel.add(button2);
frame.add(painel);
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Very good. Only needed to put correctly the Imports of the classes used in the example and send to EDT.
– user28595
I thought I didn’t need to.
– Denis Benjamim