日期:2014-05-20 浏览次数:20851 次
import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import javax.swing.text.PlainDocument; public class FilterJComboBox extends JComboBox{ private FilterJComboBox self; // private UpperCaseDocument upperCaseDocument; private MyDocumentListener documentListener; private JTextField jtf; private String[] listItems ; public static void main(String...args){ JFrame frame = new JFrame("FilterJComboBoxTest"); FilterJComboBox filterComboBox = new FilterJComboBox(); frame.getContentPane().add(filterComboBox); frame.setVisible(true); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // BasicComboBoxEditor b; } public FilterJComboBox(){ super(); self = this; this.setEditable(true); this.setModel(new FilterModel()); jtf = (JTextField)this.getEditor().getEditorComponent(); // upperCaseDocument = new UpperCaseDocument(jtf); // upperCaseDocument.SetOnlyFirstLetterCapitalize(true); documentListener = new MyDocumentListener(); io
protected synchronized final void writeLock() { try { while ((numReaders > 0) || (currWriter != null)) { if (Thread.currentThread() == currWriter) { if (notifyingListeners) { // Assuming one doesn't do something wrong in a // subclass this should only happen if a // DocumentListener tries to mutate the document. throw new IllegalStateException( "Attempt to mutate in notification"); } numWriters++; return; } wait(); } currWriter = Thread.currentThread(); numWriters = 1; } catch (InterruptedException e) { throw new Error("Interrupted attempt to aquire write lock"); } }