I would like to put a label in a JDialog, but above the buttons there. How can I do this? I get all the components online:
private void jFormattedNumMatriculaComercialMouseClicked(java.awt.event.MouseEvent evt) {
JButton botaoSIM = new JButton("Sim");
JButton botaoNAO = new JButton("Não");
JDialog dialog = new JDialog();
JLabel mensagem = new JLabel("TESTE");
botaoSIM.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jFormattedNumMatriculaComercial.setText(jFormattedNIPC.getText());
jFormattedNumMatriculaComercial.setForeground(Color.black);
jFormattedNumMatriculaComercial.requestFocus();
dialog.dispose();
}
});
botaoNAO.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
JPanel content = new JPanel();
content.add(botaoSIM);
content.add(botaoNAO);
content.add(mensagem);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.getContentPane().add(content);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}
EDIT:TheCodeislikethisnow.Withthefirst'if'Ihavealreadysolvedthequestionofopeningthewindowtwice,butbypressingno,IhavemaderequestFocusforanotherfieldbutitappearstometwice:
privatevoidjFormattedNumMatriculaComercialFocusGained(java.awt.event.FocusEventevt){if(jFormattedNumMatriculaComercial.getText().equals(" ")){
if(jFormattedNIPC.getText().equals(" ")){}
else{
int opcao = JOptionPane.showOptionDialog(null,
"Número igual ao NIF/NIPC ?",
"Número de Matrícula Comercial",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE,
null,
new String[]{"Sim", "Não"},
"default");
if (opcao == JOptionPane.YES_OPTION) {
jFormattedNumMatriculaComercial.setText(jFormattedNIPC.getText());
nomeOfContasC.requestFocus();
} else { nomeOfContasC.requestFocus();
}
}
}else {}
}