Java Code Examples for javax.swing.DefaultComboBoxModel#getSelectedItem()

The following examples show how to use javax.swing.DefaultComboBoxModel#getSelectedItem() . 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: NamedQueryModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void validateState() {
  final DefaultComboBoxModel queries = getQueries();
  setQuerySelected( queries.getSelectedItem() != null );

  if ( queries.getSelectedItem() == null ) {
    setPreviewPossible( false );
    return;
  }

  final DataSetQuery o = (DataSetQuery) queries.getSelectedItem();
  if ( o == null || StringUtils.isEmpty( o.getQueryName() ) ) {
    setPreviewPossible( false );
    return;
  }

  setPreviewPossible( true );
}
 
Example 2
Source File: SummaryTablePanel.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
private void updateStatisticsComboBox() {
    String newName = Statistic.GRANULARITY_MAXIMUM.getName(gui.getGranularity());

    @SuppressWarnings("unchecked")
    DefaultComboBoxModel<Object> model = (DefaultComboBoxModel<Object>) ((JComboBox<Object>) statsPanel
            .getComponent(1)).getModel();

    boolean reselect = false;

    if (model.getSelectedItem() == model.getElementAt(4)) {
        reselect = true;
    }

    model.removeElementAt(4);
    model.insertElementAt(newName, 4);

    if (reselect) {
        model.setSelectedItem(newName);
    }
}
 
Example 3
Source File: ConnectToServerDialog.java    From openAGV with Apache License 2.0 5 votes vote down vote up
private void cbComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbComboBoxActionPerformed
  DefaultComboBoxModel<ConnectionParamSet> model
      = (DefaultComboBoxModel<ConnectionParamSet>) cbComboBox.getModel();
  ConnectionParamSet cb = (ConnectionParamSet) model.getSelectedItem();

  if (cb != null) {
    textFieldDescription.setText(cb.getDescription());
    textFieldServer.setText(cb.getHost());
    textFieldPort.setText(String.valueOf(cb.getPort()));
  }
}
 
Example 4
Source File: ConnectionPanel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void propertyChange(final PropertyChangeEvent aEvent)
{
  final DataSourceDialogModel theDialogModel = (DataSourceDialogModel) aEvent.getSource();
  final DefaultComboBoxModel theConnections = theDialogModel.getConnections();
  final Object theConnection = theConnections.getSelectedItem();
  if (theConnection != null)
  {
    dataSourceList.setSelectedValue(theConnection, true);
  }
  else
  {
    dataSourceList.clearSelection();
  }
}
 
Example 5
Source File: NamedDataSourceDialogModel.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void contentsChanged(final ListDataEvent e)
{
  final DefaultComboBoxModel connections = getConnections();
  final DataSetComboBoxModel<String> queries = getQueries();
  setConnectionSelected(connections.getSelectedItem() != null);
  setQuerySelected(queries.getSelectedItem() != null);

  if (connections.getSelectedItem() == null)
  {
    setPreviewPossible(false);
    return;
  }

  if (queries.getSelectedItem() == null)
  {
    setPreviewPossible(false);
    return;
  }

  final DataSetQuery o = (DataSetQuery) queries.getSelectedItem();
  if (o == null || StringUtils.isEmpty(o.getQueryName()))
  {
    setPreviewPossible(false);
    return;
  }

  setPreviewPossible(true);
}
 
Example 6
Source File: CoordinateViewerTopComponent.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
public void componentOpened() {
   // TODO add custom code on component opening
   aModel = OpenSimDB.getInstance().getCurrentModel();
   if (aModel==null){
      jModelNameLabel.setText("No Models");
      hasModel=false;
      coords = null;    // Don't keep reference to old model's coordinates to avoid memory leak'
      mapCoordinates2Sliders.clear();
      updateAvailability();
      updatePosesPopup();
      return;
   }
   else if (aModel instanceof ModelForExperimentalData){
       jModelNameLabel.setText("");
      coords = null;    // Don't keep reference to old model's coordinates to avoid memory leak'
      mapCoordinates2Sliders.clear();
      hasModel = false;
      updateAvailability();
      updatePosesPopup();
      return;
   }
   openSimContext = OpenSimDB.getInstance().getContext(aModel);
   hasModel=true;
   if (ViewDB.getInstance().getModelSavedSettings(aModel)==null)
      modelHasFile = false;
   else{
      modelHasFile=true;
      prefs=ViewDB.getInstance().getModelSavedSettings(aModel).getPrefs();
   }
   jModelNameLabel.setText(aModel.getName());
   if (aModel.getNumCoordinates()==0) return;
   coords = aModel.getCoordinateSet();
   updateAvailability();
   Vector<String> coordinateGroupNames = new Vector<String>();
   for(int i=0; i<coords.getNumGroups(); i++)
      coordinateGroupNames.add(coords.getGroup(i).getName());
   groupsComboBoxModel = new DefaultComboBoxModel(coordinateGroupNames);
   jCoordinateGroupsComboBox.setModel(groupsComboBoxModel);
   String currentGroupName= (String)groupsComboBoxModel.getSelectedItem();
   //currentGroup = coords.getGroup(currentGroupName);
   // Create CoordinateSliderWithBox for each coordinate and add them to the ScrollPane
   updateDisplayGroup();
   ViewDB.getInstance().updateModelDisplay(OpenSimDB.getInstance().getCurrentModel());
   updatePosesPopup();
}