Java Code Examples for javax.swing.JComboBox#putClientProperty()

The following examples show how to use javax.swing.JComboBox#putClientProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorPanel.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 2
Source File: GuiUtils.java    From sc2gears with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: ComboBoxAutoCompleteSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: ComboBoxAutoCompleteSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: EditorPanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * @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;
}
 
Example 6
Source File: DefaultGridCellEditor.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
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;
	}
 
Example 7
Source File: ComboBoxAutoCompleteSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void setIgnoreSelectionEvents( JComboBox combo, boolean ignore ) {
    combo.putClientProperty( "nb.combo.autocomplete.ignoreselection", ignore ); //NOI18N
}
 
Example 8
Source File: ComboBoxAutoCompleteSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void setIgnoreSelectionEvents( JComboBox combo, boolean ignore ) {
    combo.putClientProperty( "nb.combo.autocomplete.ignoreselection", ignore ); //NOI18N
}