//Example modified from http://www.crionics.com/products/opensource/faq/swing_ex/JTableExamples2.html
/**
* @version 1.0 12/03/98
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.util.StringTokenizer;
public class SmallCellComboExample extends JFrame {
public SmallCellComboExample() {
super( "SmallCell Combo Example" );
DefaultTableModel dm = new DefaultTableModel(4,10) {
public void setValueAt(Object obj, int row, int col) {
StringTokenizer st;
if (obj != null) {
String str;
if (obj instanceof String) {
st=new StringTokenizer((String)obj,"-");
str =st.nextToken();
} else {
str = obj.toString();
}
super.setValueAt(str, row, col);
}
}
};
JTable table = new JTable( dm );
String[] str = {
"Time - To Time",
"Vaction - Vacation",
"Holiday - Holiday",
"8 - Work hour"
};
SteppedComboBox combo = new SteppedComboBox(str) {
public void contentsChanged(ListDataEvent e) {
selectedItemReminder = null;
super.contentsChanged(e);
}
};
Dimension d = combo.getPreferredSize();
combo.setPopupWidth(d.width);
DefaultCellEditor editor = new DefaultCellEditor(combo);
table.setDefaultEditor(Object.class, editor);
JScrollPane scroll = new JScrollPane( table );
getContentPane().add(scroll, BorderLayout.CENTER);
}
public static void main(String[] args) {
SmallCellComboExample frame = new SmallCellComboExample();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
}
});
frame.setSize( 300, 120 );
frame.setVisible(true);
}
}