Created
April 4, 2011 03:15
-
-
Save kimukou/901093 to your computer and use it in GitHub Desktop.
AutoCompletablleComboBox.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AutoCompletablleComboBox Test | |
// | |
// refarence http://itpro.nikkeibp.co.jp/article/COLUMN/20110329/358840/?ST=develop&P=1 | |
// http://griffon.codehaus.org/SwingxBuilder | |
// | |
@Grab(group='org.swinglabs', module='swingx', version='1.6.1') | |
@Grab(group='org.codehaus.griffon', module='swingxbuilder', version='0.1.7') | |
import java.awt.FlowLayout; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.JComboBox; | |
import javax.swing.JComponent; | |
import javax.swing.JLabel; | |
import javax.swing.JFrame; | |
import javax.swing.SwingUtilities; | |
import javax.swing.border.EmptyBorder; | |
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator; | |
import javax.swing.WindowConstants as WC | |
//import groovy.swing.SwingXBuilder | |
import groovy.swing.SwingBuilder | |
//public class AutoCompletableComboBox { | |
private String[] keywords = [ | |
"", | |
"abstract", "assert", "boolean", "break", | |
"byte", "case", "catch", "char", | |
"class", "const", "continue", "default", | |
"do", "double", "else", "enum", | |
"extends", "final", "finally", "float", | |
"for", "goto", "if", "implements", | |
"import", "instanceof", "int", "interface", | |
"long", "native", "new", "package", | |
"private", "protected", "public", "return", | |
"short", "static", "strictfp", "super", | |
"switch", "synchronized", "this", "throw", | |
"throws", "transient", "try", "void", | |
"volatile", "while" | |
]; | |
//private JComboBox comboBox; | |
//private JLabel label; | |
def swing | |
//public AutoCompletableComboBox() { | |
swing = new SwingBuilder() | |
def frame = swing.edt(){ | |
frame(title:"Auto Complete ComboBox" | |
,size:[300,84] | |
//,pack: true | |
,location: [50,50] | |
,resizable: true | |
,locationByPlatform:true | |
,show: true | |
//,defaultCloseOperation:WC.EXIT_ON_CLOSE //GroovyConsoleが閉じてしまうのでコメント | |
) { | |
emptyBorder([10,10,10,10], parent:true) | |
flowLayout(alignment :FlowLayout.LEFT, hgap:10,vgap:0) | |
//createComboBox() | |
comboBox( | |
id:'cb', | |
items:keywords, | |
editable:true, | |
actionPerformed:{event-> lb.text = event.source.selectedItem} | |
) | |
AutoCompleteDecorator.decorate(cb) | |
label(id:'lb',text:"") | |
} | |
//} | |
/* | |
JFrame frame = new JFrame("Auto Complete ComboBox"); | |
frame.setSize(300, 84); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
((JComponent)frame.getContentPane()).setBorder(new EmptyBorder(10, 10, 10, 10)); | |
frame.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0)); | |
frame.add(createComboBox()); | |
label = new JLabel(""); | |
frame.add(label); | |
frame.setVisible(true); | |
*/ | |
} | |
/* | |
def comboBox | |
private def createComboBox() { | |
comboBox = swing.comboBox( | |
items:keywords, | |
editable:true, | |
actionPerformed:{event-> | |
swing.lb.text = event.source.selectedItem | |
} | |
) | |
//comboBox = new JComboBox(keywords); | |
// 候補以外の文字列を入力できるようにする | |
//comboBox.setEditable(true); | |
// オートコンプリート機能を付加する | |
AutoCompleteDecorator.decorate(comboBox); | |
// イベント処理 | |
//comboBox.addActionListener(new ActionListener() { | |
// public void actionPerformed(ActionEvent event) { | |
// // 選択された文字列をラベルに表示 | |
// String selectedItem = (String)comboBox.getSelectedItem(); | |
// label.setText(selectedItem); | |
// } | |
//}); | |
//return comboBox; | |
} | |
*/ | |
//public static void main(String[] args) { | |
//SwingUtilities.invokeLater(new Runnable() { | |
// public void run() { | |
// new AutoCompletableComboBox(); | |
// } | |
//}); | |
//} | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment