ä»å㯠Input DialogããInput Dialog ã¯ã¦ã¼ã¶ã¼ã«ãæååã®å ¥åããããã¯ãé ç®ã®é¸æããæ±ãããã¤ã¢ãã°ã§ãã
Input Dialog
Input Dialog ã表示ãããã«ã¯ javax.swing.JOptionPane ã® static ã¡ã½ãã showInputDialog() ã¡ã½ããã使ç¨ãã¾ããããã®ã¡ã½ããã®ã·ã°ããã£ã¯ãããªæãï¼
static String showInputDialog(Object message) static String showInputDialog(Object message, Object initialSelectionValue) static String showInputDialog(Component parent, Object message) static String showInputDialog(Component parent, Object message, Object initialSelectionValue) static String showInputDialog(Component parent, Object message, String title, int messageType) static Object showInputDialog(Component parent, Object message, String title, int messageType, Icon icon, Object[] selectionValues, Object initialSelectionValue)
1çªç®ã2çªç®ã¯è¦ªã³ã³ãã¼ãã³ããæå®ããªããã®ã§ããããããã3çªç®ã4çªç®ã§ parent ã« null ãæå®ãããã®ã¨åããã¨ãã以ä¸ã§ã¯çç¥ããå¼æ°ã®è©³ç´°ã¯ãããªæãï¼
å¼æ° | å | å¿ é | ããã©ã«ãå¤ | 説æ |
---|---|---|---|---|
parent | java.awt.Component | No | null | 親ã¨ãªã GUI ã³ã³ãã¼ãã³ã |
message | Object | Yes | - | ã¡ãã»ã¼ã¸ |
title | String | No | "å ¥å" | ãã¤ã¢ãã°ã®ã¿ã¤ãã« |
messageType | int | No | JOptionPane. QUESTION_MESSAGE |
ã¡ãã»ã¼ã¸ã»ã¿ã¤ã |
icon | javax.swing.Icon | No | ã¢ã¤ã³ã³ | |
selectionValues | Object[] | No | é¸æå¯è½ãªé ç® | |
initialSelectionValue | Object | No | selectionValues[0] | åæã«é¸æãããé ç® |
messageType ã«é¢ãã¦ã¯ä»¥åã®è¨äºåç §ã
ãµã³ãã«ã³ã¼ã
ã§ã¯ãµã³ãã«ã³ã¼ããã次ã®2ã¤ã«åãã¦è¦ã¦ããã¾ãï¼
- æååãå ¥åãããã¤ã¢ãã°
- é ç®ãé¸æãããã¤ã¢ãã°
æååãå ¥åãããã¤ã¢ãã°
ã¾ãã¯æååãå ¥åãããã¤ã¢ãã°ã
import javax.swing.*; import static javax.swing.JOptionPane.*; JFrame parent = ...; // ä¸å³ ä¸ result = JOptionPane.showInputDialog(parent, "Here is a message."); // ä¸å³ ä¸ result = JOptionPane.showInputDialog(parent, "Here is a message.", "Initial Selection Value"); // ä¸å³ ä¸ result = JOptionPane.showInputDialog(parent, "Here is a message.", "Input Dialog", INFORMATION_MESSAGE);
åæ§ã®ãã¤ã¢ãã°ã Groovy + SwingBuilder ã使ã£ã¦è¡¨ç¤ºããã¦ã¿ã¾ãããããä¸å³ä¸çªä¸ã®ãã¤ã¢ãã°ã表示ãããã«ã¯ä¸è¨ã®ããã«ãã¾ãï¼åæå¤ã®æååãæå®ãã¦ãã¾ãï¼ï¼
import groovy.swing.SwingBuilder import static javax.swing.JOptionPane.* JFrame parent = ... def pane = new SwingBuilder().optionPane( message:'Here is a message.', messageType:INFORMATION_MESSAGE, optionType:OK_CANCEL_OPTION, wantsInput:true, initialSelectionValue:'Initial Selection Value') pane.createDialog(parent, 'Input Dialog').visible = true def result = pane.inputValue
å ¥åãããå¤ã®åå¾ããã«ã¯ inputValue ããããã£ãèªã¿åãã¾ããããäºè§£ãããåæ¶ããããÃãã®ãããã®æä½ãããããã¯ååã¨åãã value ããããã£ã«ãã£ã¦åå¾ãã¾ãã
é ç®ãé¸æãããã¤ã¢ãã°
次ã¯é ç®ãé¸æãããã¤ã¢ãã°ãããã®è¨äºæåã«è¼ãã showInputDialog() ã¡ã½ããã®ãã¡ãä¸çªä¸ã®ãã®ã使ãã¾ãã
import javax.swing.*; import static javax.swing.JOptionPane.*; JFrame parent = ...; Object[] selectionValues = {"Java", "Groovy", "Scala", "Clojure", "Vistage"}; Object result = JOptionPane.showInputDialog(parent, "Here is a message.", "Input Dialog", INFORMATION_MESSAGE, null, selectionValues, "Java");
Java ã§ã® Object ã®é
åã®ä½æã£ã¦ãããªãã§ãã£ã¦ãã£ãï¼ãã¾ããã¨ãããå®è¡çµæã¯ãããªæãï¼
Groovy + SwingBuilder ã§æ¸ãã¨ä»¥ä¸ã®ããã«ãªãã¾ãï¼
import groovy.swing.SwingBuilder import static javax.swing.JOptionPane.* JFrame parent = ... def items = ['Java', 'Groovy', 'Scala', 'Clojure', 'Vistage'] def pane = new SwingBuilder().optionPane( message:'Here is a message.', messageType:INFORMATION_MESSAGE, optionType:OK_CANCEL_OPTION, selectionValues:items, initialSelectionValue:'Java') pane.createDialog(parent, 'Input Dialog').visible = true def result = pane.inputValue
é¸æãããå¤ã®åå¾æ¹æ³ã¯ãæååãå
¥åãããã¤ã¢ãã°ãã®å ´åã¨åãã§ãã
Java Swing Hacks âä»æ¥ãã使ããé©ãã®GUIããã°ã©ãã³ã°é
- ä½è : Joshua Marinacci,Chris Adamson,ç¥æ¸åä¹(ç£è¨³),島ç°ç§é(ç£è¨³),å è¤æ ¶å½¦
- åºç社/ã¡ã¼ã«ã¼: ãªã©ã¤ãªã¼ã¸ã£ãã³
- çºå£²æ¥: 2006/04/01
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
- è³¼å ¥: 7人 ã¯ãªãã¯: 100å
- ãã®ååãå«ãããã° (38件) ãè¦ã