Java Code Examples for javax.swing.JComboBox.addItem()

The following are Jave code examples for showing how to use addItem() of the javax.swing.JComboBox class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: VASSAL-src   File: RestrictCommands.java   Source Code and License Vote up 6 votes
public Ed(RestrictCommands piece) {

      box = new JPanel();
      box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));

      name = new StringConfigurer(null, "Description:  ", piece.name);
      box.add(name.getControls());

      actionOption = new JComboBox();
      actionOption.addItem(HIDE);
      actionOption.addItem(DISABLE);
      actionOption.setSelectedIndex((piece.action.equals(HIDE)) ? 0 : 1);
      Box b = Box.createHorizontalBox();
      b.add(new JLabel("Restriction:  "));
      b.add(actionOption);
      box.add(b);

      propertyMatch = new PropertyExpressionConfigurer(null, "Restrict when properties match:  ", piece.propertyMatch, Decorator.getOutermost(piece));
      box.add(propertyMatch.getControls());

      watchKeys = new NamedKeyStrokeArrayConfigurer(null, "Restrict these Key Commands  ", piece.watchKeys);
      box.add(watchKeys.getControls());

    }
 
Example 2
Project: DIA-Umpire-Maven   File: AlignWindow.java   Source Code and License Vote up 5 votes
/**
 * Populates a combobox with an array of strings and selects the default
 *
 * @param combobox combobox to be populated
 * @param items    array of strings to be added to the combobox
 * @param selected the default selected item
 */
private void populateComboBox(JComboBox combobox, Collection<String> items, String selected) {
    String item;
    Iterator<String> i = items.iterator();
    int index = 0;
    while (i.hasNext()) {
        item = (String) i.next();
        combobox.addItem(item);
        if (item.equals(selected)) {
            combobox.setSelectedIndex(index);
        }
        index++;
    }
}
 
Example 3
Project: Logisim   File: BitWidth.java   Source Code and License Vote up 5 votes
@Override
public java.awt.Component getCellEditor(BitWidth value) {
	JComboBox<BitWidth> combo = new JComboBox<BitWidth>(choices);
	if (value != null) {
		int wid = value.getWidth();
		if (wid <= 0 || wid > prefab.length) {
			combo.addItem(value);
		}
		combo.setSelectedItem(value);
	}
	return combo;
}
 
Example 4
Project: QN-ACTR-Release   File: StatsPanel.java   Source Code and License Vote up 5 votes
private void createComboTransf() {
	transfs = new JComboBox();
	transfs.setToolTipText(TRANSF_COMBO);
	transfs.addItem("Logarithmic");
	transfs.addItem("Mix - Max");
	transfs.addItem("z-score (Standard Deviation)");
}
 
Example 5
Project: incubator-netbeans   File: TargetMappingPanel.java   Source Code and License Vote up 5 votes
private void updateCombos(boolean selectDefaults) {
    // In case you go back and choose a different script:
    Iterator<TargetDescriptor> descriptors = targetDescs.iterator();
    for (JComboBox combo : combos) {
        TargetDescriptor desc = descriptors.next();
        combo.removeAllItems();
        for (String name : targetNames) {
            combo.addItem(name);
        }
        if (selectDefaults) {
            selectItem(combo, desc.getDefaultTargets(), false); // NOI18N
        }
    }
}
 
Example 6
Project: ramus   File: TableCellEditorFactory.java   Source Code and License Vote up 5 votes
private TableCellEditor createPrintForEditor() {
    JComboBox box = new JComboBox();
    box.addItem(null);
    box.addItem(PRINT_FOR_ALL);
    box.addItem(PRINT_FOR_HAVE_CHILDS);
    box.addItem(PRINT_FOR_HAVE_NO_CHILDS);
    return new DefaultCellEditor(box);
}
 
Example 7
Project: rapidminer   File: ParameterValueKeyCellEditor.java   Source Code and License Vote up 5 votes
private JComboBox createParameterCombo(String operatorName, PropertyTable propertyTable) {
	JComboBox combo = new JComboBox();

	Operator operator = process.getOperator((String) operatorCombo.getSelectedItem());
	if (operator != null) {
		Iterator<ParameterType> i = operator.getParameters().getParameterTypes().iterator();
		while (i.hasNext()) {
			combo.addItem(i.next().getKey());
		}
	}

	if (combo.getItemCount() == 0) {
		combo.addItem("no parameters");
	}

	combo.addItemListener(new ItemListener() {

		@Override
		public void itemStateChanged(ItemEvent e) {
			fireParameterChangedEvent();
			fireEditingStopped();
		}
	});

	combo.setSelectedIndex(0);

	return combo;
}
 
Example 8
Project: jdk8u-jdk   File: MetalworksPrefs.java   Source Code and License Vote up 5 votes
public JPanel buildConnectingPanel() {
    JPanel connectPanel = new JPanel();
    connectPanel.setLayout(new ColumnLayout());

    JPanel protoPanel = new JPanel();
    JLabel protoLabel = new JLabel("Protocol");
    JComboBox protocol = new JComboBox();
    protocol.addItem("SMTP");
    protocol.addItem("IMAP");
    protocol.addItem("Other...");
    protoPanel.add(protoLabel);
    protoPanel.add(protocol);

    JPanel attachmentPanel = new JPanel();
    JLabel attachmentLabel = new JLabel("Attachments");
    JComboBox attach = new JComboBox();
    attach.addItem("Download Always");
    attach.addItem("Ask size > 1 Meg");
    attach.addItem("Ask size > 5 Meg");
    attach.addItem("Ask Always");
    attachmentPanel.add(attachmentLabel);
    attachmentPanel.add(attach);

    JCheckBox autoConn = new JCheckBox("Auto Connect");
    JCheckBox compress = new JCheckBox("Use Compression");
    autoConn.setSelected(true);

    connectPanel.add(protoPanel);
    connectPanel.add(attachmentPanel);
    connectPanel.add(autoConn);
    connectPanel.add(compress);
    return connectPanel;
}
 
Example 9
Project: QN-ACTR-Release   File: GraphPanel.java   Source Code and License Vote up 5 votes
/**
 * Builds a new LinesTable
 */
public LinesTable() {
	super(new LinesTableModel());
	setDefaultRenderer(Color.class, new ColorCellEditor());
	setDefaultRenderer(String.class, ComboBoxCellEditor.getRendererInstance());
	// Sets column sizes
	getColumnModel().getColumn(0).setMaxWidth(30);
	getColumnModel().getColumn(1).setPreferredWidth(80);
	getColumnModel().getColumn(2).setPreferredWidth(80);
	setRowHeight(18);

	// Creates class editors (one is for utilizations)
	JComboBox classCombo = new JComboBox();
	// Null elements
	classCombo.addItem("");
	// Aggregate measures
	classCombo.addItem(AGGREGATE);
	for (int i = 0; i < model.getClasses(); i++) {
		classCombo.addItem(model.getClassNames()[i]);
	}

	// Creates station editor
	JComboBox stationsCombo = new JComboBox();
	JComboBox uStationsCombo = new JComboBox();
	stationsCombo.addItem("");
	uStationsCombo.addItem("");
	stationsCombo.addItem(AGGREGATE);
	uStationsCombo.addItem(ExactConstants.GRAY_S + AGGREGATE + ExactConstants.GRAY_E);
	for (int i = 0; i < model.getStations(); i++) {
		stationsCombo.addItem(model.getStationNames()[i]);
		uStationsCombo.addItem(model.getStationNames()[i]);
	}

	// Creates editors
	classEditor = new ComboEditor(classCombo);
	uStationsEditor = new ComboEditor(uStationsCombo);
	stationsEditor = new ComboEditor(stationsCombo);
}
 
Example 10
Project: routerapp   File: SpecialGraphWindow.java   Source Code and License Vote up 5 votes
/**
  * Returns the suported Layouts from selected factory 
  */
 public void getSuportedLayouts(JComboBox cb, JComboBox r){
 	Vector layoutOptionsVector = ((GraphFactory)bType.getSelectedItem()).getSupportedLayouts();
 	r.removeAllItems();
/*if(layoutOptionsVector.size()==0)
	layoutOptionsVector.add(new CircleLayout(null));*/
Iterator iterator = layoutOptionsVector.iterator();
Object obj;
while (iterator.hasNext()){
	obj = iterator.next();
	r.addItem(obj);
}
SpecialGraphWindow.getInstance().setVisible(true);
 }
 
Example 11
Project: ramus   File: LineStyleAttributePlugin.java   Source Code and License Vote up 5 votes
@Override
public TableCellEditor getTableCellEditor(final Engine engine,
                                          final AccessRules rules, final Attribute attribute) {
    final JComboBox box = new JComboBox();
    box.setRenderer(comboBoxRenderer);

    for (Stroke stroke : LineStyleChooser.getStrokes()) {
        box.addItem(stroke);
    }

    return new DefaultCellEditor(box) {
        private Pin pin;

        @Override
        public boolean stopCellEditing() {
            if (box.getSelectedItem() instanceof Stroke) {
                ((Journaled) engine).startUserTransaction();
                apply((BasicStroke) box.getSelectedItem(), pin);
                return super.stopCellEditing();
            }
            return false;
        }

        @Override
        public Component getTableCellEditorComponent(JTable table,
                                                     Object value, boolean isSelected, int row, int column) {
            pin = (Pin) ((MetadataGetter) table).getMetadata();
            return super.getTableCellEditorComponent(table, value,
                    isSelected, row, column);
        }
    };
}
 
Example 12
Project: OpenDA   File: VariationPerParameterTableController.java   Source Code and License Vote up 5 votes
public void populateTypeComboBox(JComboBox comboBox) {

		ArrayList<VariationFunctionContext> typeList;

		typeList = this.variationFunctionContextList;
		for (VariationFunctionContext context : typeList) {
			comboBox.addItem(context);
		}

		comboBox.setSelectedItem(this.defaultVariationFunctionContext);
	}
 
Example 13
Project: Equella   File: ItemStatusAccessControlTab.java   Source Code and License Vote up 5 votes
@Override
public void init(Component parent)
{
	JLabel text = new JLabel(CurrentLocale.get("security.editor.itemstatus")); //$NON-NLS-1$

	statuses = new JComboBox();

	for( ItemStatus status : ItemStatus.values() )
	{
		statuses.addItem(status);
	}

	statuses.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent e)
		{
			saveCurrentSelection();
			loadCurrentSelection();
		}
	});

	editor = new AccessEditor(clientService.getService(RemoteTLEAclManager.class),
		clientService.getService(RemoteUserService.class));

	final int height1 = statuses.getPreferredSize().height;
	final int width1 = text.getPreferredSize().width;

	final int[] rows = {height1, TableLayout.FILL,};
	final int[] cols = {width1, TableLayout.DOUBLE_FILL, TableLayout.FILL,};

	setLayout(new TableLayout(rows, cols));
	add(text, new Rectangle(0, 0, 1, 1));
	add(statuses, new Rectangle(1, 0, 1, 1));
	add(editor, new Rectangle(0, 1, 3, 1));
}
 
Example 14
Project: ramus   File: SectorNameEditor.java   Source Code and License Vote up 5 votes
protected void createReplacementPanel(JPanel panel) {
    panel.add(getReplacemetPanel(), java.awt.BorderLayout.CENTER);
    JPanel aligmentPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    aligmentPanel.add(new JLabel(ResourceLoader.getString("Aligment")));
    aligments = new JComboBox();
    aligments.addItem(ResourceLoader.getString("Aligment.Left"));
    aligments.addItem(ResourceLoader.getString("Aligment.Center"));
    aligments.addItem(ResourceLoader.getString("Aligment.Right"));
    aligmentPanel.add(aligments);
    this.add(aligmentPanel, java.awt.BorderLayout.CENTER);
}
 
Example 15
Project: Equella   File: MapperTab.java   Source Code and License Vote up 5 votes
private JComponent createTop()
{
	JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
	mappingBox = new JComboBox();
	mappingBox.addItem(new IMSMapping(schema));
	mappingBox.addItem(new HTMLMapping(schema));
	mappingBox.addItem(new ScriptedLiteralMapping(schema));
	mappingBox.addItemListener(this);
	panel1.add(mappingBox);
	return panel1;
}
 
Example 16
Project: ProyectoPacientes   File: Cita.java   Source Code and License Vote up 4 votes
public String ColocarDoctoresCBX(JComboBox ListaDoctores)
{
//LO QUE SE QUIERE LOGRAR    
    //CONECTAR A LA BASE DE DATOS
    Conexion nuevaConexion = new Conexion();//creamos un objeto de la clase
    Connection conex ; //variable tipo coneccion 
//---------------------------------------------------------------------------------------------------------------    
    //objeto donde quedan los resultados
    ResultSet consulta = null; //se adaptara a la tabla de la base de datos para que obtenga los datos
//---------------------------------------------------------------------------------------------------------------    
    
    //INSERTAR EL REGISTRO QUE TENGA EN LA TABLA DE LA BASE DE DATOS
    try
    {
        nuevaConexion.Conectar(); //para que se ejecute el metodo de coneccion creado anteriormente
        
        conex = nuevaConexion.getConexion(); //le asignamos a conex la CONEXION creada con anterioridad en el metodo
        
        Statement comando = conex.createStatement();//preparamos un COMANDO para poder ejecutar
        
        
        
        //JOptionPane.showMessageDialog(null, "Usuario: "+usuario+"   ContraseƱa: "+Pass);
    //ejecutamos LA CONSULTA 
        consulta = comando.executeQuery("select * from doctores "); //es "Query" porque solo CONSULTAMOS 
                      //NO cambiaremos nada                            
                                        //usamos el "select *" para que seleccione todo 
                                                                                                    
    //Otra forma -------------------------------------------FORMA ORIGINAL-------------------------------------------------------------------------------------------------------
    //---------------si se hace de esta forma RECORDAR colocar la validacion cuando los campos ESTAN VACIOS en el formulario-----------------------------------------------------
        //Variables a utilizar
        String apelDoc="";
        
        //para obtener los datos actuales
        while(consulta.next()==true)
        {
            //asignacion de los datos a las variables
            apelDoc = consulta.getString("Apellidos"); //en " " va el nombre de la columna en la base de datos                
            
            //para colocarlo en el combobox
            ListaDoctores.addItem(apelDoc);//le asignamos el nombre de la unidad al bombobox del JDvisitas             
            
        }            
    //----------------------------------------------------------------------------------------------------------------------------------------------------------------------    
       
    
    
        
        conex.close();//para cerrar la base de datos
    
        //retorne que si se agrego
        return "consulta realizada exitosamente";   
    
    }
    catch(Exception e)
    {
        //JOptionPane.showMessageDialog(null, "Usuario NO existente: "+e);
        
        //retorne que no se agrego
         return "A ocurrido un error al realizar la consulta"+e;              
    }
    
}
 
Example 17
Project: ramus   File: SectorColorAttributePlugin.java   Source Code and License Vote up 4 votes
@Override
public TableCellEditor getTableCellEditor(final Engine engine,
                                          final AccessRules rules, final Attribute attribute) {
    final JComboBox box = new JComboBox();
    box.setRenderer(comboBoxRenderer);

    box.addItem(Color.white);
    box.addItem(Color.green);
    box.addItem(Color.blue);
    box.addItem(Color.red);
    box.addItem(Color.yellow);
    box.addItem(Color.cyan);
    box.addItem(Color.magenta);
    box.addItem(Color.orange);
    box.addItem(Color.pink);
    box.addItem(Color.lightGray);
    box.addItem(Color.gray);
    box.addItem(Color.darkGray);
    box.addItem(Color.black);

    return new DefaultCellEditor(box) {
        private Pin pin;

        @Override
        public boolean stopCellEditing() {
            if (box.getSelectedItem() instanceof Color) {
                ((Journaled) engine).startUserTransaction();
                apply((Color) box.getSelectedItem(), pin);
                return super.stopCellEditing();
            }
            return false;
        }

        @Override
        public Component getTableCellEditorComponent(JTable table,
                                                     Object value, boolean isSelected, int row, int column) {
            pin = (Pin) ((MetadataGetter) table).getMetadata();
            return super.getTableCellEditorComponent(table, value,
                    isSelected, row, column);
        }
    };
}
 
Example 18
Project: VASSAL-src   File: Immobilized.java   Source Code and License Vote up 4 votes
public Ed(Immobilized p) {
  selectionOption = new JComboBox();
  selectionOption.addItem("normally");
  selectionOption.addItem("when shift-key down");
  selectionOption.addItem("when alt-key down");
  selectionOption.addItem("never");
  if (p.neverSelect) {
    selectionOption.setSelectedIndex(3);
  }
  else if (p.altToSelect) {
    selectionOption.setSelectedIndex(2);
  }
  else if (p.shiftToSelect) {
    selectionOption.setSelectedIndex(1);
  }
  else {
    selectionOption.setSelectedIndex(0);
  }
  ignoreGridBox = new JCheckBox("Ignore map grid when moving?");
  ignoreGridBox.setSelected(p.ignoreGrid);
  controls = Box.createVerticalBox();
  Box b = Box.createHorizontalBox();
  b.add(new JLabel("Select piece:  "));
  b.add(selectionOption);
  controls.add(b);

  movementOption = new JComboBox();
  movementOption.addItem("normally");
  movementOption.addItem("only if selected");
  movementOption.addItem("never");
  if (p.neverMove) {
    movementOption.setSelectedIndex(2);
  }
  else if (p.moveIfSelected) {
    movementOption.setSelectedIndex(1);
  }
  else {
    movementOption.setSelectedIndex(0);
  }
  b = Box.createHorizontalBox();
  b.add(new JLabel("Move piece:  "));
  b.add(movementOption);
  controls.add(b);
  controls.add(ignoreGridBox);
}
 
Example 19
Project: zooracle   File: ToadDataPanel.java   Source Code and License Vote up 4 votes
public ToadDataPanel(DisplayMode displayMode)
{
	super(displayMode);
	

	comboBoxPopulation = new JComboBox(); 
	for (Object item : Locale.dropDownPopulations)
		comboBoxPopulation.addItem(item);	
	comboBoxPopulation.setPreferredSize(new Dimension(iw, lh));
	
	textFieldSize1 = new JTextField("");   textFieldSize1.setPreferredSize(new Dimension(iw, 30)); textFieldSize1.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	textFieldSize2 = new JTextField("");   textFieldSize2.setPreferredSize(new Dimension(iw, 30)); textFieldSize2.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	textFieldWeight = new JTextField("");   textFieldWeight.setPreferredSize(new Dimension(iw, 30)); textFieldWeight.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	textFieldTotal = new JTextField("");   textFieldTotal.setPreferredSize(new Dimension(iw, 30)); textFieldTotal.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	textFieldTotal.setEditable(false);
	
	labelPopulation =     GUISettings.getDefaultLabel(Locale.labelPopulation, lw, lh, a, va);  
	labelSize1 =          GUISettings.getDefaultLabel(Locale.labelSize1, lw, lh, a, va);  		
	labelSize2 =          GUISettings.getDefaultLabel(Locale.labelSize2, lw, lh, a, va);  		
	labelSizeTotal =      GUISettings.getDefaultLabel(Locale.labelSizeTotal, lw, lh, a, va);  		
	labelWeight =         GUISettings.getDefaultLabel(Locale.labelWeight, lw, lh, a, va);  		

	JPanel panelSize1                   = new JPanel(new FlowLayout(orientation)); 
	JPanel panelSize2                   = new JPanel(new FlowLayout(orientation)); 
	JPanel panelSizeTotal               = new JPanel(new FlowLayout(orientation)); 
	JPanel panelWeight                  = new JPanel(new FlowLayout(orientation)); 
	JPanel panelPopulation              = new JPanel(new FlowLayout(orientation)); 
	
	if (currentDisplayMode.equals(DisplayMode.vertical_align_left))
	{
		panelSize1.add(textFieldSize1);		
		panelSize1.add(labelSize1);
		panelSize2.add(textFieldSize2);		
		panelSize2.add(labelSize2);
		panelSizeTotal.add(textFieldTotal);		
		panelSizeTotal.add(labelSizeTotal);
		panelWeight.add(textFieldWeight);		
		panelWeight.add(labelWeight);
		panelPopulation.add(comboBoxPopulation);
		panelPopulation.add(labelPopulation);
	}
	else
	{
		panelSize1.add(labelSize1);
		panelSize1.add(textFieldSize1);		
		panelSize2.add(labelSize2);
		panelSize2.add(textFieldSize2);		
		panelSizeTotal.add(labelSizeTotal);
		panelSizeTotal.add(textFieldTotal);		
		panelWeight.add(labelWeight);
		panelWeight.add(textFieldWeight);		
		panelPopulation.add(labelPopulation);
		panelPopulation.add(comboBoxPopulation);
	}
	
	inputLabels.add(labelSize1);
	inputLabels.add(labelSize2);
	inputLabels.add(labelSizeTotal);
	inputLabels.add(labelWeight);
	inputLabels.add(labelPopulation);

	JPanel toadDataPanel = new JPanel();
	toadDataPanel.setLayout(new BoxLayout(toadDataPanel, BoxLayout.Y_AXIS));
	toadDataPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black, 1), Locale.labelToadData));
	
	toadDataPanel.add(panelPopulation);
	toadDataPanel.add(panelSize1);
	toadDataPanel.add(panelSize2);
	toadDataPanel.add(panelSizeTotal);
	toadDataPanel.add(panelWeight);
	JPanel placeholder = new JPanel();
	toadDataPanel.add(placeholder);
	
	
	dataPanel.add(toadDataPanel);
	
}
 
Example 20
Project: ProyectoPacientes   File: LLenarCombo.java   Source Code and License Vote up 2 votes
public void Presentar (JComboBox esp)
    {
        Conexion nconexion = new Conexion();  //objeto de la clase conexion
        Connection conex; 
         //vector horizontal que corresponde a cada columna de la tabla
        
        
        try
        {
            nconexion.Conectar(); // ejecuta el metodo conectar de la clase conexion el que contiene la direccion de la base de datos 
            conex = nconexion.getConexion();  //aca se retorna la conexion que se obtuvo
            Statement comando = conex.createStatement(); //comando para poder ejecutar executeUpdate
            
           
         
            ResultSet consulta = comando.executeQuery("select * from especialidades");
        
            String aux=""; 
            while(consulta.next()==true )
               
            {
                aux= consulta.getString("Especialidad");
                System.out.print(aux);
                esp.addItem(aux);
            }
            conex.close(); //para cerrar en la base de datos 
            
              
           
          
            //conex.close() sirve para cerrar la conexion si se ejecuta la parte del codigo anterior 
           
        }
        
        catch(Exception e)
        {
            
            JOptionPane.showMessageDialog(null, "Especialidad no encontrada" +e); 
        }
    
}