Java Code Examples for java.awt.Choice#select()

The following examples show how to use java.awt.Choice#select() . 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: SignUI.java    From Websocket-Smart-Card-Signer with GNU Affero General Public License v3.0 5 votes vote down vote up
private void updateComboBox(Choice certificateComboBox){
    certificateComboBox.removeAll();
    certificateComboBox.addItem("Loading Certificates...");
    certificateComboBox.select(0);
   
    ArrayList<CertificateData> certList = new ArrayList<CertificateData>();
    try {
        certList = signEngine.loadSmartCardCertificateList(readAllCertificates).certificateList;
    } catch (Exception e) {
        e.printStackTrace();
        SignUtils.playBeeps(1);
        JOptionPane.showMessageDialog(null, "ERROR LOADING CERTIFICATES:\n"+e.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
    }
    
    certificateComboBox.removeAll();
    certificateComboBox.addItem("--Select Certificate--");
    for(int i=0;i<certList.size();i++)
        certificateComboBox.addItem(certList.get(i).id);
    
    if(certificateComboBox.getItemCount()==1){
        certificateComboBox.removeAll();
        certificateComboBox.addItem("--No Certificates Available!--");
        SignUtils.playBeeps(2);
    }
    else{
        if(certificateComboBox.getItemCount()==2){
            certificateComboBox.remove(0);
        }
        SignUtils.playBeeps(1);
    }
}
 
Example 2
Source File: DrawTableValuesPlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void replaceStrings(Choice choice, String[] strings, String defaultString)
{
    choice.removeAll();
       for (String str : strings) 
       {
           choice.add(str);
       }
       choice.select(defaultString);
}
 
Example 3
Source File: PrintfApplet.java    From KEEL with GNU General Public License v3.0 4 votes vote down vote up
private void initInputPanel(Panel p) {
   GridBagConstraints gbc=
     new GridBagConstraints();
   p.setLayout(new GridBagLayout());
   gbc.weightx=100;
   gbc.weighty=100;
   gbc.gridwidth=1;
   gbc.gridheight=1;
   gbc.fill=GridBagConstraints.HORIZONTAL;
   gbc.anchor=GridBagConstraints.WEST;

   gbc.gridx=0;
   gbc.gridy=0;
   Label typeLabel=new Label("Type");
   p.add(typeLabel,gbc);
   gbc.gridx=1;
   gbc.gridwidth=GridBagConstraints.REMAINDER;
   Label valueLabel=new Label("Value");
   p.add(valueLabel,gbc);

   gbc.gridx=0;
   gbc.gridy=1;
   Choice type=new Choice();
   type.add("Byte");
   type.add("Short");
   type.add("Character");
   type.add("Integer");
   type.add("Long");
   type.add("Float");
   type.add("Double");
   type.add("String");
   type.add("Object");
   type.select("Float");
   type.addItemListener(new TypeChoiceCommand());
   p.add(type,gbc);
   gbc.gridx=1;
   gbc.gridwidth=GridBagConstraints.REMAINDER;
   value=new ValueChoice();
   p.add(value,gbc);

   gbc.gridx=0;
   gbc.gridy=2;
   gbc.gridwidth=1;
   gbc.fill=GridBagConstraints.NONE;
   Button reset=new Button("Reset");
   reset.addActionListener(new ResetCommand());
   p.add(reset,gbc);
   gbc.gridx=1;
   gbc.gridwidth=GridBagConstraints.REMAINDER;
   Button position=new Button("Add");
   position.addActionListener(new AddCommand());
   p.add(position,gbc);

gbc.gridx=0;
gbc.gridy=3;
   gbc.gridwidth=1;
   gbc.gridheight=GridBagConstraints.REMAINDER;
   gbc.fill=GridBagConstraints.HORIZONTAL;
   Label format = new Label("Control String");
   p.add(format,gbc);
gbc.gridx=1;
   TextField formatString = new TextField(40);
   gbc.gridwidth=GridBagConstraints.REMAINDER;
   formatString.addTextListener(new FormatCommand());
   p.add(formatString,gbc);
 }
 
Example 4
Source File: LabelToValuePlugin.java    From MorphoLibJ with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean dialogItemChanged(GenericDialog gd, AWTEvent evt) 
{
	if (gd.wasCanceled() || gd.wasOKed()) 
	{
		return true;
	}
	
	@SuppressWarnings("rawtypes")
	Vector choices = gd.getChoices();
	if (choices == null) 
	{
		IJ.log("empty choices array...");
		return false;
	}
	
	// Change of the data table
       if (evt.getSource() == choices.get(0)) 
	{
		String tableName = ((Choice) evt.getSource()).getSelectedItem();
		Frame tableFrame = WindowManager.getFrame(tableName);
		this.table = ((TextWindow) tableFrame).getTextPanel().getResultsTable();
		
		// Choose current heading
		String[] headings = this.table.getHeadings();
		String defaultHeading = headings[0];
		if (defaultHeading.equals("Label") && headings.length > 1) 
		{
			defaultHeading = headings[1];
		}
		
		Choice headingChoice = (Choice) choices.get(1);
		headingChoice.removeAll();
		for (String heading : headings) 
		{
			headingChoice.add(heading);
		}
		headingChoice.select(defaultHeading);

		changeColumnHeader(defaultHeading);
	}
	
	// Change of the column heading
	if (evt.getSource() == choices.get(1)) 
	{
		String headerName = ((Choice) evt.getSource()).getSelectedItem();
           changeColumnHeader(headerName);
	}
	
	return true;
}