javax.swing.JComboBox#putClientProperty ( )源码实例Demo

下面列出了javax.swing.JComboBox#putClientProperty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gcs   文件: EditorPanel.java
/**
 * @param compare The current string compare object.
 * @param extra   The extra text to add to the menu item.
 * @return The {@link JComboBox} that allows a string comparison to be changed.
 */
protected JComboBox<Object> addStringCompareCombo(StringCriteria compare, String extra) {
    Object[] values;
    Object   selection;
    if (extra == null) {
        values = StringCompareType.values();
        selection = compare.getType();
    } else {
        List<String> list = new ArrayList<>();
        selection = null;
        for (StringCompareType type : StringCompareType.values()) {
            String title = extra + type;
            list.add(title);
            if (type == compare.getType()) {
                selection = title;
            }
        }
        values = list.toArray();
    }
    JComboBox<Object> combo = addComboBox(COMPARISON, values, selection);
    combo.putClientProperty(StringCriteria.class, compare);
    return combo;
}
 
源代码2 项目: sc2gears   文件: GuiUtils.java
/**
 * Creates a combo box whose value is bound to the specified settingKey.<br>
 * The initial value of the combo box will be taken from the {@link Settings},
 * and an action listener will be added to the combo box to register changes at the {@link Settings}.
 * 
 * @param valueVector         vector of initial values of the combo box
 * @param settingKey          key of the settings its value is bound to
 * @param useSmallSizeVariant tells is small size variant feature of the Nimbus should be used
 * @return the created combo box
 */
public static <T> JComboBox< T > createComboBox( final Vector< T > valueVector, final String settingKey, final boolean useSmallSizeVariant ) {
	final JComboBox< T > comboBox = new JComboBox<>( new CustomComboBoxModel< T >( valueVector ) ); 
	
	try {
		comboBox.setSelectedIndex( Settings.getInt( settingKey ) );
	} catch ( final IllegalArgumentException iae ) {
		comboBox.setSelectedIndex( Settings.getDefaultInt( settingKey ) );
	}
	
	comboBox.addActionListener( new ActionListener() {
		@Override
		public void actionPerformed( final ActionEvent event ) {
			Settings.set( settingKey, comboBox.getSelectedIndex() );
		}
	} );
	
	if ( useSmallSizeVariant ) {
		comboBox.putClientProperty( "JComponent.sizeVariant", "small" );
		comboBox.updateUI();
	}
	
	return comboBox;
}
 
源代码3 项目: netbeans   文件: ComboBoxAutoCompleteSupport.java
public static boolean install( JComboBox combo ) {
    boolean res = false;
    ComboBoxEditor comboEditor = combo.getEditor();
    if( comboEditor.getEditorComponent() instanceof JTextComponent ) {
        JTextComponent textEditor = ( JTextComponent ) comboEditor.getEditorComponent();
        Document doc = textEditor.getDocument();
        doc.addDocumentListener( new AutoCompleteListener( combo ) );
        setIgnoreSelectionEvents( combo, false );
        combo.setEditable( true );
        res = true;
    }
    combo.putClientProperty( "nb.combo.autocomplete", res ); //NOI18N
    return res;
}
 
源代码4 项目: netbeans   文件: ComboBoxAutoCompleteSupport.java
public static boolean install( JComboBox combo ) {
    boolean res = false;
    ComboBoxEditor comboEditor = combo.getEditor();
    if( comboEditor.getEditorComponent() instanceof JTextComponent ) {
        JTextComponent textEditor = ( JTextComponent ) comboEditor.getEditorComponent();
        Document doc = textEditor.getDocument();
        doc.addDocumentListener( new AutoCompleteListener( combo ) );
        setIgnoreSelectionEvents( combo, false );
        combo.setEditable( true );
        res = true;
    }
    combo.putClientProperty( "nb.combo.autocomplete", res ); //NOI18N
    return res;
}
 
源代码5 项目: gcs   文件: EditorPanel.java
/**
 * @param compare The current integer compare object.
 * @param extra   The extra text to add to the menu item.
 * @return The {@link JComboBox} that allows a comparison to be changed.
 */
protected JComboBox<Object> addNumericCompareCombo(NumericCriteria compare, String extra) {
    Object       selection = null;
    List<String> list      = new ArrayList<>();
    for (NumericCompareType type : NumericCompareType.values()) {
        String title = extra == null ? type.toString() : extra + type.getDescription();
        list.add(title);
        if (type == compare.getType()) {
            selection = title;
        }
    }
    JComboBox<Object> combo = addComboBox(COMPARISON, list.toArray(), selection);
    combo.putClientProperty(NumericCriteria.class, compare);
    return combo;
}
 
public Component getEditorComponent(int row, int column, Object value,
			boolean isSelected, JGrid grid, boolean recreate) {
		if (editorComponent instanceof JComboBox) {
			final JComboBox comboBox = new JComboBox();
			editorComponent = comboBox;
			comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
		        delegate = new EditorDelegate() {
		        	public void setValue(Object value) {
		        		comboBox.setSelectedItem(value);
		            }

		        	public Object getCellEditorValue() {
		        		return comboBox.getSelectedItem();
		        	}
		                
		            public boolean shouldSelectCell(EventObject anEvent) { 
		                if (anEvent instanceof MouseEvent) { 
		                    MouseEvent e = (MouseEvent)anEvent;
		                    return e.getID() != MouseEvent.MOUSE_DRAGGED;
		                }
		                return true;
		            }
		            
		            public boolean stopCellEditing() {
		            	if (comboBox.isEditable()) {
		            		// 	Commit edited value.
		            		comboBox.actionPerformed(new ActionEvent(DefaultGridCellEditor.this, 0, ""));
		            	}
		            	return super.stopCellEditing();
		            }
		        };
			comboBox.addActionListener(delegate);
		}
        this.grid = grid;
//		editorComponent.setBorder(new LineBorder(Color.black));
		delegate.setValue(value);
		
		return editorComponent;
	}
 
源代码7 项目: netbeans   文件: ComboBoxAutoCompleteSupport.java
static void setIgnoreSelectionEvents( JComboBox combo, boolean ignore ) {
    combo.putClientProperty( "nb.combo.autocomplete.ignoreselection", ignore ); //NOI18N
}
 
源代码8 项目: netbeans   文件: ComboBoxAutoCompleteSupport.java
static void setIgnoreSelectionEvents( JComboBox combo, boolean ignore ) {
    combo.putClientProperty( "nb.combo.autocomplete.ignoreselection", ignore ); //NOI18N
}