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

The following examples show how to use javax.swing.JComboBox#setBackground() . 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: Query.java    From OpenDA with GNU Lesser General Public License v3.0 6 votes vote down vote up
/** Create a choice menu.
 *  @param name The name used to identify the entry (when calling get).
 *  @param label The label to attach to the entry.
 *  @param values The list of possible choices.
 *  @param defaultChoice Default choice.
 *  @param editable True if an arbitrary choice can be entered, in addition
 *   to the choices in values.
 *  @param background The background color for the editable part.
 */
public void addChoice(
        String name,
        String label,
        String[] values,
        String defaultChoice,
        boolean editable,
        Color background) {
    JLabel lbl = new JLabel(label + ": ");
    lbl.setBackground(_background);
    JComboBox combobox = new JComboBox(values);
    combobox.setEditable(editable);
    // FIXME: Typical of Swing, the following does not set
    // the background color.  How does one set the background
    // color?
    combobox.setBackground(background);
    combobox.setSelectedItem(defaultChoice);
    _addPair(name, lbl, combobox, combobox);
    // Add the listener last so that there is no notification
    // of the first value.
    combobox.addItemListener(new QueryItemListener(name));
}
 
Example 2
Source File: ExampleSourceConfigurationWizardValueTypeTable.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	List<String> usedTypes = new LinkedList<String>();
	for (int i = 0; i < Ontology.VALUE_TYPE_NAMES.length; i++) {
		if ((i != Ontology.ATTRIBUTE_VALUE) && (i != Ontology.FILE_PATH)
				&& (!Ontology.ATTRIBUTE_VALUE_TYPE.isA(i, Ontology.DATE_TIME))) {
			usedTypes.add(Ontology.ATTRIBUTE_VALUE_TYPE.mapIndex(i));
		}
	}
	String[] valueTypes = new String[usedTypes.size()];
	int vCounter = 0;
	for (String type : usedTypes) {
		valueTypes[vCounter++] = type;
	}
	JComboBox<String> typeBox = new JComboBox<>(valueTypes);
	typeBox.setBackground(javax.swing.UIManager.getColor("Table.cellBackground"));
	return new DefaultCellEditor(typeBox);
}
 
Example 3
Source File: RemoteExecutionDialog.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
private static JComboBox<String> buildProductFormatNamesComboBox(Insets defaultListItemMargins, int textFieldPreferredHeight, String[] availableFormatNames) {
    JComboBox<String> productFormatNameComboBox = new JComboBox<String>(availableFormatNames);
    Dimension formatNameComboBoxSize = productFormatNameComboBox.getPreferredSize();
    formatNameComboBoxSize.height = textFieldPreferredHeight;
    productFormatNameComboBox.setPreferredSize(formatNameComboBoxSize);
    productFormatNameComboBox.setMinimumSize(formatNameComboBoxSize);
    LabelListCellRenderer<String> renderer = new LabelListCellRenderer<String>(defaultListItemMargins) {
        @Override
        protected String getItemDisplayText(String value) {
            return value;
        }
    };
    productFormatNameComboBox.setMaximumRowCount(5);
    productFormatNameComboBox.setRenderer(renderer);
    productFormatNameComboBox.setBackground(new Color(0, 0, 0, 0)); // set the transparent color
    productFormatNameComboBox.setOpaque(true);

    return productFormatNameComboBox;
}
 
Example 4
Source File: ExampleSourceConfigurationWizardAttributeTypeTable.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public TableCellEditor getCellEditor(int row, int column) {
	JComboBox<String> typeBox = new JComboBox<>(Attributes.KNOWN_ATTRIBUTE_TYPES);
	typeBox.setEditable(true);
	typeBox.setBackground(javax.swing.UIManager.getColor("Table.cellBackground"));
	return new DefaultCellEditor(typeBox);
}
 
Example 5
Source File: JComboBoxFactory.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
private static<T> void setComboBoxProperties(JComboBox<T> comboBox, ImageInfoReader imageInfoReader) {
	comboBox.setOpaque(false);
	comboBox.setBackground(ColorPalette.FOREGROUND_COLOR);
	comboBox.setForeground(ColorPalette.FOREGROUND_COLOR);
	comboBox.setFont(Fonts.FONT);
	
	comboBox.setUI(new MetalComboBoxUI() {

		@Override
		protected ComboPopup createPopup() {
			return new TiledImageComboPopup( comboBox, imageInfoReader );
		}
	});
}
 
Example 6
Source File: JPlagCreator.java    From jplag with GNU General Public License v3.0 5 votes vote down vote up
public static JComboBox<String> createJComboBox(String[] items, int width, int height, String toolTip) {

		JComboBox<String> comboBox = new JComboBox<String>(items);
		comboBox.setPreferredSize(new java.awt.Dimension(width, height));
		comboBox.setBackground(java.awt.Color.white);
		comboBox.setFont(JPlagCreator.SYSTEM_FONT);
		if (toolTip != null)
			comboBox.setToolTipText(toolTip);
		return comboBox;

	}
 
Example 7
Source File: OptionPanel.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public JComboBox addChoice(String label, String[] items, int selected, Setter setter) {
	addLabel(label);
	JComboBox choice = new JComboBox(items);
	choice.setBackground(Color.white);
	choice.setSelectedIndex(selected);
	choice.addActionListener(tl);
	all.add(choice);
	addField(choice, setter);
	return choice;
}
 
Example 8
Source File: URLImportDialog.java    From chipster with MIT License 4 votes vote down vote up
public URLImportDialog(SwingClientApplication client) {
	super(client.getMainFrame(), true);
	if(recentURLs == null){
		recentURLs = new LinkedList<String>();
	}
	
	this.client = client;
	this.setTitle("Import data from URL");
	this.setModal(true);
	
	label = new JLabel("Insert URL");
	label.setFont(label.getFont().deriveFont(Font.BOLD));
	label.setPreferredSize(LABEL_SIZE);
	
	folderNameCombo = new JComboBox(ImportUtils.getFolderNames(true).toArray());
	folderNameCombo.setEditable(true);
	
	skipCheckBox = new JCheckBox(VisualConstants.getImportDirectlyText());
	if (!Session.getSession().getApplication().isStandalone()) {
		skipCheckBox.setSelected(true);
	} else {
		skipCheckBox.setSelected(false);
	}
	
	okButton = new JButton("OK");
	okButton.setPreferredSize(BUTTON_SIZE);
	okButton.addActionListener(this);
	
	cancelButton = new JButton("Cancel");
	cancelButton.setPreferredSize(BUTTON_SIZE);
	cancelButton.addActionListener(this);
	
	String[] comboValues = new String[recentURLs.size() + 1];
	comboValues[0] = "http://";
	for(int i = 0; i < recentURLs.size(); i++){
		comboValues[i+1] = recentURLs.get(i);
	}
	URLComboBox = new JComboBox(comboValues);
	URLComboBox.setBackground(Color.WHITE);
	URLComboBox.setPreferredSize(COMBO_SIZE);
	URLComboBox.setEditable(true);
			
	GridBagConstraints c = new GridBagConstraints();
	
	this.setLayout(new GridBagLayout());
	// Label
	c.anchor = GridBagConstraints.WEST;
	c.insets.set(10, 10, 5, 10);
	c.gridx = 0; 
	c.gridy = 0;
	this.add(label, c);
	
	// Combobox
	c.insets.set(0,10,10,10);		
	c.gridy++;
	this.add(URLComboBox, c);
	
	c.insets.set(10,10,5,10);
	c.gridy++;
	this.add(new JLabel("Insert in folder"),c);
	
	c.fill = GridBagConstraints.HORIZONTAL;
	c.insets.set(0,10,10,10);
	c.gridy++;
	this.add(folderNameCombo,c);
	

	c.insets.set(10, 10, 10, 10);
	c.anchor = GridBagConstraints.EAST;
	c.gridy++;
	this.add(skipCheckBox,c);
	c.fill = GridBagConstraints.HORIZONTAL;
	c.gridy++;
	JPanel keepButtonsRightPanel = new JPanel();
	keepButtonsRightPanel.add(okButton);
	keepButtonsRightPanel.add(cancelButton);
	this.add(keepButtonsRightPanel, c);
	
	this.pack();
	this.setLocationRelativeTo(null);
	URLComboBox.requestFocusInWindow();
	this.setVisible(true);
}