Hi,
below code is to load JComboBox from
String[] and Hashtable both
---------------------------------------
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class JComboEx extends JFrame {
static String[] screenNames = {
"Auto Screen", "On Screen", "Off Screen",
"INT_xRGB", "INT_ARGB", "INT_ARGB_PRE", "INT_BGR",
"3BYTE_BGR", "4BYTE_ABGR", "4BYTE_ABGR_PRE", "USHORT_565_RGB",
"USHORT_x555_RGB", "BYTE_GRAY", "USHORT_GRAY",
"BYTE_BINARY", "BYTE_INDEXED", "BYTE_BINARY 2 bit", "BYTE_BINARY 4 bit",
"INT_RGBx", "USHORT_555x_RGB"};
static JComboBox screenCombo;
static JComboBox screenComboHash;
Hashtable hashScreenValue;
public JComboEx() {
screenCombo = new JComboBox();
screenCombo.setPreferredSize(new Dimension(120, 18));
screenCombo.setLightWeightPopupEnabled(true);
for (int i = 0; i < screenNames.length; i++) {
screenCombo.addItem(screenNames[i]);
}
// first i have to add item to the hash table
// bcoz at present i can't show with database
hashScreenValue = new Hashtable();
for (int i = 0; i < screenNames.length; i++) {
hashScreenValue.put(new Integer(i), screenNames[i]);
}
screenComboHash = new JComboBox();
screenComboHash.setPreferredSize(new Dimension(120, 18));
screenComboHash.setLightWeightPopupEnabled(true);
Enumeration enum = hashScreenValue.elements();
while(enum.hasMoreElements()){
String value = (String)enum.nextElement();
screenComboHash.addItem(value);
}
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
topPanel.add( screenCombo, BorderLayout.NORTH );
topPanel.add( new JLabel("Hello !!!"), BorderLayout.CENTER );
topPanel.add( screenComboHash, BorderLayout.SOUTH );
}
public static void main(String args[]){
JComboEx cex = new JComboEx();
cex.setSize(400,400);
cex.setVisible(true);
}
}
Bye,
Purvi Pandya