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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class ConfirmDialog extends AbstractOptionDialog {
public ConfirmDialog(Frame owner, String title, String message){
super(owner, title, message);
}
@Override
protected Component createIcon(){
Icon icon = UIManager.getIcon("OptionPane.questionIcon");
JLabel iconLabel = new JLabel(icon);
iconLabel.setVerticalAlignment(SwingConstants.TOP);
return iconLabel;
}
@Override
protected JPanel createMessagePanel(String message){
JPanel panel = new JPanel();
try {
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints cons = new GridBagConstraints();
panel.setLayout(gridbag);
cons.fill = GridBagConstraints.HORIZONTAL;
cons.weightx = 1;
cons.weighty = 0;
cons.gridy = 0;
cons.insets = new Insets(0,0,3,0);
BufferedReader br = new BufferedReader( new StringReader(message));
String line = "";
while( (line = br.readLine()) != null){
panel.add(new JLabel(line), cons);
cons.gridy++;
}
} catch (Exception e){
}
return panel;
}
@Override
protected JPanel createButtonPanel(){
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
Dimension margin = new Dimension(40, 0);
JPanel leftMargin = new JPanel();
leftMargin.setPreferredSize(margin);
JPanel rightMargin = new JPanel();
rightMargin.setPreferredSize(margin);
// 「はい」 ボタン
JButton yesButton = new JButton(UIManager.getString("OptionPane.yesButtonText"));
yesButton.setActionCommand(Integer.toString(JOptionPane.OK_OPTION));
yesButton.getInputMap().put(enterPress, "pressed");
yesButton.getInputMap().put(enterRelease, "released");
yesButton.addActionListener(this);
try {
int mnemonic = Integer.parseInt((String)UIManager.get("OptionPane.yesButtonMnemonic"));
yesButton.setMnemonic(mnemonic);
} catch (Exception e){
}
// 「いいえ」ボタン
JButton noButton = new JButton(UIManager.getString("OptionPane.noButtonText"));
noButton.setActionCommand(Integer.toString(JOptionPane.NO_OPTION));
noButton.getInputMap().put(enterPress, "pressed");
noButton.getInputMap().put(enterRelease, "released");
noButton.addActionListener(this);
try {
int mnemonic = Integer.parseInt((String)UIManager.get("OptionPane.noButtonMnemonic"));
noButton.setMnemonic(mnemonic);
} catch (Exception e){
}
panel.add(leftMargin);
panel.add(yesButton);
panel.add(noButton);
panel.add(rightMargin);
return panel;
}
public static int showDialog(Frame owner, String title, String message){
ConfirmDialog dialog = new ConfirmDialog(owner, title, message);
return dialog.showDialog();
}
} |
[通知用URL]
Tweet
最終更新時間:2011年02月19日 19時38分28秒