1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| JOptionPane jop = null ;
JTextArea textArea = new JTextArea("");
JTextField textField = new JTextField("");
JScrollPane scrollArea = new JScrollPane(textArea);
scrollArea.setPreferredSize(new Dimension(iWidth, iHeight));
int icon = JOptionPane.QUESTION_MESSAGE ;
int iReturn = 0;
Icon iIcon = null ;
if(sIconName != null)
{
Image img = loadImage(sIconName);
if(img != null) iIcon = new ImageIcon(img);
}
textField.setPreferredSize(new Dimension(iWidth, iHeight));
// dialog font
if(fDialogFont != null)
{
scrollArea.setFont(fDialogFont);
textField.setFont(fDialogFont);
textArea.setFont(fDialogFont);
}
// dialog colors
if(cDialogFore != null)
{
scrollArea.setForeground(cDialogFore);
textField.setForeground(cDialogFore);
textArea.setForeground(cDialogFore);
}
if(cDialogBack != null)
{
scrollArea.setBackground(cDialogBack);
textField.setBackground(cDialogBack);
textArea.setBackground(cDialogBack);
}
if(iIcon != null)
{
if(bMulti)
jop = new JOptionPane(new Object[] {sText, textArea},JOptionPane.QUESTION_MESSAGE,JOptionPane.OK_CANCEL_OPTION,iIcon);
else
jop = new JOptionPane(new Object[] {sText, textField},JOptionPane.QUESTION_MESSAGE,JOptionPane.OK_CANCEL_OPTION,iIcon);
}
else
{
if(bMulti)
jop = new JOptionPane(new Object[] {sText, textArea},JOptionPane.QUESTION_MESSAGE,JOptionPane.OK_CANCEL_OPTION);
else
jop = new JOptionPane(new Object[] {sText, textField},JOptionPane.QUESTION_MESSAGE,JOptionPane.OK_CANCEL_OPTION);
}
jop.setBackground(cDialogBack);
jop.setForeground(cDialogFore);
for(int i =0; i<jop.getComponentCount();i++) {
jop.getComponent(i).setBackground(cDialogBack);
}
JDialog dialog = jop.createDialog(this, sTitle);
if(iX < 0 || iY < 0) dialog.setLocationRelativeTo(formsMain.getFrame());
else dialog.setLocation(iX, iY);
dialog.setVisible(true);
Object selectedValue = jop.getValue();
if(((Integer)selectedValue).intValue() != JOptionPane.CANCEL_OPTION)
{
if(bMulti) sReturn = textArea.getText();
else sReturn = textField.getText();
} |
Partager