티스토리 뷰
Option & Message Type Values
Confirm Dialog Box
Input Dialog Box
Message Dialog Box
Option Dialog Box
Frame Source
* OPTION TYPE : 버튼 모양 정의 * - DEFAULT_OPTION * - YES_NO_OPTION * - YES_NO_CANCEL * - OK_CANCEL * * MSG TYPE : 다이얼로그 창에 메세지와 함께 뜨는 아이콘 정의 * - ERROR_MESSAGE * - INFORMATION_MESSAGE * - WARNING_MESSAGE * - QUESTION_MESSAGE * - PLAIN_MESSAGE |
Confirm Dialog Box
JOptionPane.showConfirmDialog(parentComponent, message); JOptionPane.showConfirmDialog(parentComponent, message, title, optionType); JOptionPane.showConfirmDialog(parentComponent, message, title, optionType, messageType); JOptionPane.showConfirmDialog(parentComponent, message, title, optionType, messageType, icon); Example. JOptionPane.showConfirmDialog(F, "Msg", "Title", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null); |
Input Dialog Box
JOptionPane.showInputDialog(message); JOptionPane.showInputDialog(parentComponent, message); JOptionPane.showInputDialog(message, initialSelectionValue); JOptionPane.showInputDialog(parentComponent, message, initialSelectionValue); JOptionPane.showInputDialog(parentComponent, message, title, messageType); JOptionPane.showInputDialog(parentComponent, message, title, messageType, icon, selectionValues, initialSelectionValue); - selectionValues = showOptionDialog's options : String[] - initialSelectionValue = TextField's initial Text Example. String[] st = {"a", "b", "c"}; JOptionPane.showInputDialog(F, "Msg", "Title", JOptionPane.QUESTION_MESSAGE, null, st, "c"); |
Message Dialog Box
JOptionPane.showMessageDialog(parentComponent, message); JOptionPane.showMessageDialog(parentComponent, message, title, messageType); JOptionPane.showMessageDialog(parentComponent, message, title, messageType, icon); Example. JOptionPane.showMessageDialog(F, "Msg", "Title", JOptionPane.INFORMATION_MESSAGE, null); |
Option Dialog Box
JOptionPane.showOptionDialog(parentComponent, message, title, optionType, messageType, icon, options, initialValue); - options : String[] - initialValue : String Example. String[] st = {"1", "2", "3"}; JOptionPane.showOptionDialog(F, "Msg", "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, st, "2"); |
Frame Source
import javax.swing.JFrame; import javax.swing.JButton; import javax.swing.JOptionPane; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class Frame extends JFrame { private Frame F = this; public Frame() { setTitle("Use JOptionPane"); setSize(190, 180); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(null); JButton btnNewButton = new JButton("showConfirmDialog"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JOptionPane.showConfirmDialog(F, "Msg", "Title", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null); } }); btnNewButton.setBounds(12, 10, 151, 23); getContentPane().add(btnNewButton); JButton btnNewButton_1 = new JButton("showInputDialog"); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String[] st = {"a", "b", "c"}; JOptionPane.showInputDialog(F, "Msg", "Title", JOptionPane.QUESTION_MESSAGE, null, st, "c"); } }); btnNewButton_1.setBounds(12, 43, 151, 23); getContentPane().add(btnNewButton_1); JButton btnNewButton_2 = new JButton("showMsgDialog"); btnNewButton_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(F, "Msg", "Title", JOptionPane.INFORMATION_MESSAGE, null); } }); btnNewButton_2.setBounds(12, 76, 151, 23); getContentPane().add(btnNewButton_2); JButton btnNewButton_3 = new JButton("showOptionDialog"); btnNewButton_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String[] st = {"1", "2", "3"}; JOptionPane.showOptionDialog(F, "Msg", "Title", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, st, "2"); } }); btnNewButton_3.setBounds(12, 109, 151, 23); getContentPane().add(btnNewButton_3); setVisible(true); } } |
댓글