/*
Code revised from Desktop Java Live:
http://www.sourcebeat.com/downloads/
*/
import java.util.ArrayList;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import com.jgoodies.binding.adapter.BasicComponentFactory;
import com.jgoodies.binding.adapter.ComboBoxAdapter;
import com.jgoodies.binding.value.ValueHolder;
import com.jgoodies.binding.value.ValueModel;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
public class ComboBoxAdapterExample extends JPanel {
public ComboBoxAdapterExample() {
JPanel panel = new JPanel(new FormLayout("p, 2dlu, p:g", "t:p, b:d:g"));
panel.setBorder(new EmptyBorder(6, 6, 6, 6));
ArrayList strings = new ArrayList();
strings.add("Swing");
strings.add("SWT");
strings.add("HTML");
strings.add("Flash");
strings.add("QT");
CellConstraints cc = new CellConstraints();
ValueModel selectionHolder = new ValueHolder("Select A Display Technology");
ComboBoxAdapter comboBoxAdapter = new ComboBoxAdapter(strings, selectionHolder);
JComboBox comboBox = new JComboBox();
comboBox.setModel(comboBoxAdapter);
panel.add(new JLabel("Combo Box:"), cc.xy(1, 1));
panel.add(comboBox, cc.xy(3, 1));
panel.add(new JLabel("Selection:"), cc.xy(1, 2));
panel.add(BasicComponentFactory.createTextField(selectionHolder), cc.xy(3, 2));
add(panel);
}
public static void main(String[] a){
JFrame f = new JFrame("ComboBox Adapter Example");
f.setDefaultCloseOperation(2);
f.add(new ComboBoxAdapterExample());
f.pack();
f.setVisible(true);
}
}
|