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

The following examples show how to use javax.swing.JComboBox#setOpaque() . 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: FixDuplicateImportStmts.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private JComboBox createComboBox(DataItem item, Font font, FocusListener listener) {
    List<ItemVariant> variants = item.getVariants();
    JComboBox combo = new JComboBox(variants.toArray());
    combo.setSelectedItem(item.getDefaultVariant());
    combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
    combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
    combo.setOpaque(false);
    combo.setFont(font);
    combo.addFocusListener(listener);
    combo.setEnabled(variants.size() > 1);
    combo.setRenderer(new DelegatingRenderer(combo.getRenderer(), variants, item.getVariantIcons()));
    InputMap inputMap = combo.getInputMap(JComboBox.WHEN_FOCUSED);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "showPopup"); //NOI18N
    combo.getActionMap().put("showPopup", new TogglePopupAction()); //NOI18N
    return combo;
}
 
Example 2
Source File: ControlsDialog.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
private void addPerformancePanel(KeyBindings keyBindings) {
	JPanel performancePanel = JPanelFactory.createJPanel("Performance");
	performancePanel.setOpaque(false);
	performancePanel.setBounds(15, 310, 368, 100);
	performancePanel.setLayout(null);
	
	JLabel lblAnimationSpeed = JLabelFactory.createJLabel("Animation Speed:");
	lblAnimationSpeed.setToolTipText(ANIMATION_SPEED_TOOL_TIP);
	lblAnimationSpeed.setOpaque(false);
	lblAnimationSpeed.setBounds(12, 25, 137, 25);
	performancePanel.add(lblAnimationSpeed);

	JComboBox<AnimationSpeed> cmbAnimationSpeed = JComboBoxFactory.createJComboBox(AnimationSpeed.values(), imageInfoReader);
	cmbAnimationSpeed.setForeground(Color.BLACK);
	cmbAnimationSpeed.setToolTipText(ANIMATION_SPEED_TOOL_TIP);
	cmbAnimationSpeed.setSelectedItem(keyBindings.getAnimationSpeed());
	cmbAnimationSpeed.setOpaque(false);
	cmbAnimationSpeed.setBounds(228, 25, 127, 25);
	performancePanel.add(cmbAnimationSpeed);
	
	cmbAnimationSpeed.addActionListener(e -> keyBindings.setAnimationSpeed((AnimationSpeed)cmbAnimationSpeed.getSelectedItem()));
	
	addComponent(performancePanel);
}
 
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: FixDuplicateImportStmts.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JComboBox createComboBox(CandidateDescription[] choices, CandidateDescription defaultValue, Font font, FocusListener listener ) {
    JComboBox combo = new JComboBox(choices);
    combo.setSelectedItem(defaultValue);
    combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
    combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
    combo.setOpaque(false);
    combo.setFont( font );
    combo.addFocusListener( listener );
    combo.setEnabled( choices.length > 1 );
    combo.setRenderer( new DelegatingRenderer(combo.getRenderer()));
    InputMap inputMap = combo.getInputMap( JComboBox.WHEN_FOCUSED );
    inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_SPACE, 0), "showPopup" ); //NOI18N
    combo.getActionMap().put( "showPopup", new TogglePopupAction() ); //NOI18N
    return combo;
}
 
Example 5
Source File: ImportChooserInnerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JComboBox createComboBox( String[] choices, String defaultValue, Icon[] icons, Font font, FocusListener listener ) {
    JComboBox combo = new JComboBox(choices);
    combo.setSelectedItem(defaultValue);
    combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
    combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
    combo.setOpaque(false);
    combo.setFont( font );
    combo.addFocusListener( listener );
    combo.setEnabled( choices.length > 1 );
    combo.setRenderer( new DelegatingRenderer(combo.getRenderer(), choices, icons ) );
    InputMap inputMap = combo.getInputMap( JComboBox.WHEN_FOCUSED );
    inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_SPACE, 0), "showPopup" ); //NOI18N
    combo.getActionMap().put( "showPopup", new TogglePopupAction() ); //NOI18N
    return combo;
}
 
Example 6
Source File: FixDuplicateImportStmts.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JComboBox createComboBox(DataItem item, Font font, FocusListener listener) {
    List<VariantItem> variants = item.getVariants();
    JComboBox combo = new JComboBox(variants.toArray());
    combo.setSelectedItem(item.getDefaultVariant());
    combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
    combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
    combo.setOpaque(false);
    combo.setFont(font);
    combo.addFocusListener(listener);
    combo.setEnabled(variants.size() > 1);
    InputMap inputMap = combo.getInputMap(JComboBox.WHEN_FOCUSED);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "showPopup"); //NOI18N
    combo.getActionMap().put("showPopup", new TogglePopupAction()); //NOI18N
    return combo;
}
 
Example 7
Source File: SettingsEditor.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private <E> JComboBox<E> createCombo(JPanel panel, E[] values, E choice, String tooltip) {
    JComboBox<E> combo = new JComboBox<>(values);
    combo.setOpaque(false);
    combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    combo.setSelectedItem(choice);
    combo.addActionListener(this);
    combo.setMaximumRowCount(combo.getItemCount());
    UIUtilities.setToPreferredSizeOnly(combo);
    panel.add(combo);
    return combo;
}
 
Example 8
Source File: EditorPanel.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link JComboBox}.
 *
 * @param command   The command to issue on selection.
 * @param items     The items to add to the {@link JComboBox}.
 * @param selection The item to select initially.
 * @return The new {@link JComboBox}.
 */
protected <T> JComboBox<T> addComboBox(String command, T[] items, T selection) {
    JComboBox<T> combo = new JComboBox<>(items);
    combo.setOpaque(false);
    combo.setSelectedItem(selection);
    combo.setActionCommand(command);
    combo.addActionListener(this);
    combo.setMaximumRowCount(items.length);
    UIUtilities.setToPreferredSizeOnly(combo);
    add(combo);
    return combo;
}
 
Example 9
Source File: DisplayPreferences.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private <E> JComboBox<E> createCombo(E[] values, E choice, String tooltip) {
    JComboBox<E> combo = new JComboBox<>(values);
    combo.setOpaque(false);
    combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    combo.setSelectedItem(choice);
    combo.addActionListener(this);
    combo.setMaximumRowCount(combo.getItemCount());
    UIUtilities.setToPreferredSizeOnly(combo);
    add(combo);
    return combo;
}
 
Example 10
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 11
Source File: ConnectionAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void initComponents() {
    setLayout(new BorderLayout(4, 0));
    setBorder(new EmptyBorder(0, 2, 0, 8));
    setOpaque(false);
    setFocusTraversalPolicyProvider(true);
    setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
        @Override
        public Component getDefaultComponent(Container aContainer) {
            if (!SwingUtilities.isEventDispatchThread()) {
                return null;
            }
            final EditorCookie ec = actionContext.lookup(
                    EditorCookie.class);
            if (ec != null) {
                JEditorPane[] panes = ec.getOpenedPanes();
                if (panes != null) {
                    for (JEditorPane pane : panes) {
                        if (pane.isShowing()) {
                            return pane;
                        }
                    }
                }
            }

            return null;
        }
   });

    combo = new JComboBox();
    combo.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            DatabaseConnection dbconn = (DatabaseConnection)combo.getSelectedItem();
            combo.setToolTipText(dbconn != null ? dbconn.getDisplayName() : null);
        }
    });
    combo.setOpaque(false);
    combo.setModel(new DefaultComboBoxModel(
            new String[] { NbBundle.getMessage(ToolbarPresenter.class, "ConnectionAction.ToolbarPresenter.LoadingConnections") }));

    combo.setRenderer(new DatabaseConnectionRenderer());
    String accessibleName = NbBundle.getMessage(ConnectionAction.class, "LBL_DatabaseConnection");
    combo.getAccessibleContext().setAccessibleName(accessibleName);
    combo.getAccessibleContext().setAccessibleDescription(accessibleName);
    combo.setPreferredSize (new Dimension (400, combo.getPreferredSize ().height));

    add(combo, BorderLayout.CENTER);

    comboLabel = new JLabel();
    Mnemonics.setLocalizedText(comboLabel, NbBundle.getMessage(ConnectionAction.class, "LBL_ConnectionAction"));
    comboLabel.setOpaque(false);
    comboLabel.setLabelFor(combo);
    add(comboLabel, BorderLayout.WEST);
}
 
Example 12
Source File: ClockRateModelEditor.java    From beast-mcmc with GNU Lesser General Public License v2.1 4 votes vote down vote up
public ClockRateModelEditor(PartitionDataList dataList, int row) {

		this.dataList = dataList;
		this.row = row;

		clockParameterFields = new RealNumberField[PartitionData.clockParameterNames.length];
		window = new JDialog(owner, "Setup clock rate model for partition "
				+ (row + 1));
		optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER);

		clockCombo = new JComboBox();
		clockCombo.setOpaque(false);

		for (String clockModel : PartitionData.clockModels) {
			clockCombo.addItem(clockModel);
		}// END: fill loop

		clockCombo.addItemListener(new ListenClockCombo());

		for (int i = 0; i < PartitionData.clockParameterNames.length; i++) {
			
			switch (i) {

			case 0:// clockrate
				clockParameterFields[i] = new RealNumberField(0.0, Double.MAX_VALUE);
				break;

			case 1: // ucld.mean
				clockParameterFields[i] = new RealNumberField(-Double.MAX_VALUE, Double.MAX_VALUE);
				break;

			case 2:// ucld.stdev
				clockParameterFields[i] = new RealNumberField(0.0, Double.MAX_VALUE);
				break;

			case 3: // ucld.offset
				clockParameterFields[i] = new RealNumberField(-Double.MAX_VALUE, Double.MAX_VALUE);
				break;

			case 4: // uced.mean
				clockParameterFields[i] = new RealNumberField(-Double.MAX_VALUE, Double.MAX_VALUE);
				break;

			case 5: // uced.offset
				clockParameterFields[i] = new RealNumberField(-Double.MAX_VALUE, Double.MAX_VALUE);
				break;

			case 6: // ig.mean
				clockParameterFields[i] = new RealNumberField(-Double.MAX_VALUE, Double.MAX_VALUE);
				break;

			case 7: // ig.stdev
				clockParameterFields[i] = new RealNumberField(0.0, Double.MAX_VALUE);
				break;

			case 8: // ig.offset
				clockParameterFields[i] = new RealNumberField(-Double.MAX_VALUE, Double.MAX_VALUE);
				break;

			default:
				clockParameterFields[i] = new RealNumberField();
			}// END: parameter switch
			
			clockParameterFields[i].setColumns(8);
			clockParameterFields[i]
					.setValue(dataList.get(row).clockParameterValues[i]);
		}// END: fill loop

		setClockArguments();

		// Buttons
		JPanel buttonsHolder = new JPanel();
		buttonsHolder.setOpaque(false);
		
		cancel = new JButton("Cancel", Utils.createImageIcon(Utils.CLOSE_ICON));
		cancel.addActionListener(new ListenCancel());
		buttonsHolder.add(cancel);
		
		done = new JButton("Done", Utils.createImageIcon(Utils.CHECK_ICON));
		done.addActionListener(new ListenOk());
		buttonsHolder.add(done);
		
		// Window
		owner = Utils.getActiveFrame();
		window.setLocationRelativeTo(owner);
		window.getContentPane().setLayout(new BorderLayout());
		window.getContentPane().add(optionPanel, BorderLayout.CENTER);
		window.getContentPane().add(buttonsHolder, BorderLayout.SOUTH);
		window.pack();
		
		// return to the previously chosen index on start
		clockCombo.setSelectedIndex(dataList.get(row).clockModelIndex);
		
	}
 
Example 13
Source File: DemographicModelEditor.java    From beast-mcmc with GNU Lesser General Public License v2.1 4 votes vote down vote up
public DemographicModelEditor(PartitionDataList dataList, int row) {
	
	this.dataList = dataList;
	this.row = row;
	
	demographicParameterFields = new RealNumberField[PartitionData.demographicParameterNames.length];
	window = new JDialog(owner, "Setup tree model for partition " + (row + 1));
	optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER);
	
	demographicCombo = new JComboBox();
	demographicCombo.setOpaque(false);

	for (String demographicModel : PartitionData.demographicModels) {
		demographicCombo.addItem(demographicModel);
	}// END: fill loop

	demographicCombo.addItemListener(new ListenDemographicCombo());
	
	for (int i = 0; i < PartitionData.demographicParameterNames.length; i++) {
		demographicParameterFields[i] = new RealNumberField(0.0, Double.MAX_VALUE);
		demographicParameterFields[i].setColumns(8);
		demographicParameterFields[i].setValue(this.dataList.get(row).demographicParameterValues[i]);
	}// END: fill loop

	setDemographicArguments();

	// Buttons
	JPanel buttonsHolder = new JPanel();
	buttonsHolder.setOpaque(false);
	
	cancel = new JButton("Cancel", Utils.createImageIcon(Utils.CLOSE_ICON));
	cancel.addActionListener(new ListenCancel());
	buttonsHolder.add(cancel);
	
	done = new JButton("Done", Utils.createImageIcon(Utils.CHECK_ICON));
	done.addActionListener(new ListenOk());
	buttonsHolder.add(done);
	
	// Window
	owner = Utils.getActiveFrame();
	window.setLocationRelativeTo(owner);
	window.getContentPane().setLayout(new BorderLayout());
	window.getContentPane().add(optionPanel, BorderLayout.CENTER);
	window.getContentPane().add(buttonsHolder, BorderLayout.SOUTH);
	window.pack();
	
	//return to the previously chosen index on start
	demographicCombo.setSelectedIndex(dataList.get(row).demographicModelIndex);
	
}
 
Example 14
Source File: SiteRateModelEditor.java    From beast-mcmc with GNU Lesser General Public License v2.1 4 votes vote down vote up
public SiteRateModelEditor(PartitionDataList dataList, int row) throws NumberFormatException, BadLocationException {

		this.dataList = dataList;
		this.row = row;
		
		siteParameterFields = new RealNumberField[PartitionData.siteRateModelParameterNames.length];
		window = new JDialog(owner, "Setup site rate model for partition " + (row + 1));
		optionPanel = new OptionsPanel(12, 12, SwingConstants.CENTER);

		siteCombo = new JComboBox();
		siteCombo.setOpaque(false);

		for (String siteModel : PartitionData.siteRateModels) {
			siteCombo.addItem(siteModel);
		}// END: fill loop

		siteCombo.addItemListener(new ListenSiteCombo());

		for (int i = 0; i < PartitionData.siteRateModelParameterNames.length; i++) {
			
			switch (i) {

			case 0: // GammaCategories
				siteParameterFields[i] = new RealNumberField(1.0, Double.valueOf(Integer.MAX_VALUE));
				break;

			case 1: // Alpha
				siteParameterFields[i] = new RealNumberField(0.0, Double.MAX_VALUE);
				break;

			case 2: // Invariant sites proportion
				siteParameterFields[i] = new RealNumberField(0.0, 1.0);
				break;

			default:
				siteParameterFields[i] = new RealNumberField();

			}//END: parameter switch
			
			siteParameterFields[i].setColumns(8);
			siteParameterFields[i].setValue(dataList.get(0).siteRateModelParameterValues[i]);
		}// END: fill loop

		setSiteArguments();

		// Buttons
		JPanel buttonsHolder = new JPanel();
		buttonsHolder.setOpaque(false);
		
		cancel = new JButton("Cancel", Utils.createImageIcon(Utils.CLOSE_ICON));
		cancel.addActionListener(new ListenCancel());
		buttonsHolder.add(cancel);
		
		done = new JButton("Done", Utils.createImageIcon(Utils.CHECK_ICON));
		done.addActionListener(new ListenOk());
		buttonsHolder.add(done);
		
		// Window
		owner = Utils.getActiveFrame();
		window.setLocationRelativeTo(owner);
		window.getContentPane().setLayout(new BorderLayout());
		window.getContentPane().add(optionPanel, BorderLayout.CENTER);
		window.getContentPane().add(buttonsHolder, BorderLayout.SOUTH);
		window.pack();
		
		//return to the previously chosen index on start
		siteCombo.setSelectedIndex(dataList.get(row).siteRateModelIndex);
		
	}
 
Example 15
Source File: PreferencePanel.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Sets up a {@link JComboBox} suitable for use within the preference panel.
 *
 * @param combo   The {@link JComboBox} to prepare.
 * @param tooltip The tooltip to use.
 */
protected void setupCombo(JComboBox<?> combo, String tooltip) {
    combo.setOpaque(false);
    combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    add(combo);
}