当前位置: 首页>>代码示例>>Java>>正文


Java JComboBox.setSelectedIndex方法代码示例

本文整理汇总了Java中javax.swing.JComboBox.setSelectedIndex方法的典型用法代码示例。如果您正苦于以下问题:Java JComboBox.setSelectedIndex方法的具体用法?Java JComboBox.setSelectedIndex怎么用?Java JComboBox.setSelectedIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JComboBox的用法示例。


在下文中一共展示了JComboBox.setSelectedIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: selectInJCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
public static <T> int selectInJCombo(JComboBox<T> combo, T obj, int defaultSelectIndex)
{
	int i = selectInJCombo(combo, obj);
	if( i >= 0 )
	{
		return i;
	}
	else
	{
		int count = combo.getItemCount();
		if( defaultSelectIndex < count )
		{
			combo.setSelectedIndex(defaultSelectIndex);
		}
		else if( count > 0 )
		{
			combo.setSelectedIndex(count - 1);
		}
		return combo.getSelectedIndex();
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:AppletGuiUtils.java

示例2: showInfo

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * Show information about a host
 * @param host Host to show the information of
 */
@SuppressWarnings("unchecked")
public void showInfo(DTNHost host) {
	Vector messages = new Vector<Message>(host.getMessageCollection());
	Collections.sort(messages);
	reset();
	this.selectedHost = host;
	String text = (host.isActive() ? "" : "INACTIVE ") + host + " at " +
		host.getLocation();
	
	msgChooser = new JComboBox(messages);
	msgChooser.insertItemAt(messages.size() + " messages", 0);
	msgChooser.setSelectedIndex(0);
	msgChooser.addActionListener(this);
	
	routingInfoButton = new JButton("routing info");
	routingInfoButton.addActionListener(this);
	
	this.add(new JLabel(text));
	this.add(msgChooser);
	this.add(routingInfoButton);
	this.revalidate();
}
 
开发者ID:mdonnyk,项目名称:the-one-mdonnyk,代码行数:27,代码来源:InfoPanel.java

示例3: ReportProductionPanel

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * The constructor that will add the items to this panel.
 *
 * FIXME: can we extend this to cover farmed goods?
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 */
public ReportProductionPanel(FreeColClient freeColClient) {
    super(freeColClient, "reportProductionAction");

    this.goodsTypes = transform(getSpecification().getGoodsTypeList(),
                                gt -> !gt.isFarmed());
    List<String> goodsNames = transform(this.goodsTypes, alwaysTrue(),
                                        gt -> Messages.getName(gt));
    goodsNames.add(0, Messages.message("nothing"));
    String[] model = goodsNames.toArray(new String[0]);
    for (int index = 0; index < NUMBER_OF_GOODS; index++) {
        JComboBox<String> newBox = new JComboBox<>(model);
        newBox.setSelectedIndex(0);
        this.boxes.add(newBox);
    }

    reportPanel.setLayout(new MigLayout("gap 0 0", "[fill]", "[fill]"));
    update();
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:26,代码来源:ReportProductionPanel.java

示例4: KMeanScatterPanelChoose

import javax.swing.JComboBox; //导入方法依赖的package包/类
public KMeanScatterPanelChoose(WorkloadAnalysisSession m) {
	super(new BorderLayout());
	setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), "Scatter Clustering"));

	model = (ModelWorkloadAnalysis) m.getDataModel();
	this.session = m;

	varXCombo = new JComboBox(model.getMatrix().getVariableNames());
	varYCombo = new JComboBox(model.getMatrix().getVariableNames());
	varXCombo.setSelectedIndex(0);
	varYCombo.setSelectedIndex(1);

	JButton vis = new JButton(VIS_SCATTER);

	JPanel combos = new JPanel(new GridLayout(1, 2, 5, 0));
	combos.add(varXCombo);
	combos.add(varYCombo);

	add(combos, BorderLayout.NORTH);
	add(vis, BorderLayout.SOUTH);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:22,代码来源:KMeanScatterPanelChoose.java

示例5: Ed

import javax.swing.JComboBox; //导入方法依赖的package包/类
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());

    }
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:25,代码来源:RestrictCommands.java

示例6: addQueryHistory

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * Add the query to the history
 */
private void addQueryHistory(String queryString) {
    JComboBox<String> query = getQueryField();
    query.removeItem(queryString);
    query.insertItemAt(queryString, 0);
    query.setSelectedIndex(0);
    while (query.getItemCount() > MAX_HISTORY) {
        query.removeItemAt(MAX_HISTORY);
    }

    // store the history
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < query.getItemCount(); i++) {
        if (i > 0) {
            sb.append("\n");
        }
        sb.append(query.getItemAt(i));
    }
    PREFS.put("queryHistory", sb.toString());
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:23,代码来源:PrologDisplay.java

示例7: getLon

import javax.swing.JComboBox; //导入方法依赖的package包/类
String getLon(Point2D pt, JComboBox box){
	DecimalFormat fmt = new DecimalFormat("#.#");
	String degStartX = (""+pt.getX()).split("\\.")[0];
	String startRest = (""+pt.getX()).split("\\.")[1];

	if(degreesOrMinutes.getSelectedIndex()==0){
		if(pt.getX()>180){
			return fmt.format((-1)*(360.0 - pt.getX()));
		}
		return fmt.format(pt.getX());
	}

	Double minStartX; 
	if(startRest.length()>2){
		String convertStartMinX = startRest.substring(0, 2)+"."+startRest.substring(2,startRest.length());
		minStartX = Double.parseDouble(convertStartMinX)*(60.0/100.0);	
	}
	else
		minStartX = Double.parseDouble(startRest)*(60.0/100.0);

	if(degStartX.substring(0, 1).equals("-")){
		box.setSelectedIndex(1);
		degStartX = degStartX.substring(1,degStartX.length());
	}
	else if(Double.parseDouble(degStartX) > 180){
		degStartX = ""+(360 - Double.parseDouble(degStartX));
		box.setSelectedIndex(1);
	}else{
		box.setSelectedIndex(0);
	}
	return (degStartX + " " + fmt.format(minStartX));
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:33,代码来源:GMAProfile.java

示例8: TaxDialog

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * Set up and show the dialog. The first Component argument determines which
 * frame the dialog depends on; it should be a component in the dialog's
 * controlling frame. The second Component argument should be null if you
 * want the dialog to come up with its left corner in the center of the
 * screen; otherwise, it should be the component on top of which the dialog
 * should appear.
 */

public TaxDialog(Component frameComp, Component locationComp,
		String title,  I_TickerManager tickerManager) {
	super(frameComp, locationComp, title, tickerManager);

	String[] currencies = {"EUR", "USD", "SEK" , "NOK"};
	currencyList = new JComboBox(currencies);
	currencyList.setEditable(true);
	currencyList.addActionListener(this);
	currencyList.setSelectedIndex(0);
	currencyList.setActionCommand(CURRENCY_CHANGED);
	
	totalCostField = new JTextField(FIELD_LEN);
	totalCostField.setEditable(true);
	totalCostField.setText("");		
	totalCostField.addKeyListener(this);
	
	dateFieldLabel = new JLabel("Maksupäivä: ");
	dateFieldLabel.setLabelFor(dateChooser);


	totalCostFieldLabel = new JLabel("yhteensä: ");
	totalCostFieldLabel.setLabelFor(totalCostField);

	currencyFieldLabel = new JLabel("Valuutta: ");
	
	updateRateFieldCcy((String) currencyList.getSelectedItem(), true);
	init(getDialogLabels(), getDialogComponents());
}
 
开发者ID:skarna1,项目名称:javaportfolio,代码行数:38,代码来源:TaxDialog.java

示例9: setColor

import javax.swing.JComboBox; //导入方法依赖的package包/类
static void setColor (JComboBox<ColorValue> combo, Color color) {
    if (color == null) {
        combo.setSelectedIndex (content.length - 1);
    } else {
        combo.setSelectedItem (new ColorValue (color));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ColorComboBox.java

示例10: testBasic

import javax.swing.JComboBox; //导入方法依赖的package包/类
public void testBasic() {
    JComboBox comboBox = new JComboBox();
    ListModelImpl listModel = new ListModelImpl();
    DataModelImpl dataModel = new DataModelImpl(listModel);
    DataComboBoxSupport support = new DataComboBoxSupport(comboBox, dataModel, true);

    assertSame(support.NEW_ITEM, comboBox.getItemAt(0));
    assertEquals("Add", comboBox.getItemAt(0).toString());
    assertEquals(-1, comboBox.getSelectedIndex());

    List items = new ArrayList();
    items.add("foo");
    items.add("bar");
    listModel.setItems(items);

    assertEquals("foo", comboBox.getItemAt(0));
    assertEquals("bar", comboBox.getItemAt(1));
    assertEquals("Add", comboBox.getItemAt(2).toString());
    assertEquals("The old selected item was removed, nothing should be selected now", -1, comboBox.getSelectedIndex());

    comboBox.setSelectedIndex(1); // bar
    items.remove("foo");
    listModel.setItems(items);

    assertEquals("bar", comboBox.getItemAt(0));
    assertEquals("Add", comboBox.getItemAt(1).toString());
    assertEquals("Bar should still be selected", 0, comboBox.getSelectedIndex());

    items.add("new");
    listModel.setItems(items, "new");

    assertEquals("bar", comboBox.getItemAt(0));
    assertEquals("new", comboBox.getItemAt(1));
    assertEquals("Add", comboBox.getItemAt(2).toString());
    assertEquals("new", comboBox.getSelectedItem());
    assertEquals("New should be selected", 1, comboBox.getSelectedIndex());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:DataComboBoxSupportTest.java

示例11: createOperatorCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private JComboBox createOperatorCombo(final PropertyTable propertyTable) {
	List<Operator> allInnerOps = parentOperator.getAllInnerOperators();
	Vector<String> allOpNames = new Vector<String>();
	Iterator<Operator> i = allInnerOps.iterator();
	while (i.hasNext()) {
		allOpNames.add(i.next().getName());
	}
	Collections.sort(allOpNames);
	final JComboBox combo = new JComboBox(allOpNames);
	combo.addItemListener(new ItemListener() {

		@Override
		public void itemStateChanged(ItemEvent e) {
			String operatorName = (String) combo.getSelectedItem();
			panel.remove(parameterCombo);
			parameterCombo = createParameterCombo(operatorName, propertyTable);
			panel.add(parameterCombo);
			fireParameterChangedEvent();
			fireEditingStopped();
		}
	});
	if (combo.getItemCount() == 0) {
		combo.addItem("add inner operators");
	} else {
		combo.setSelectedIndex(0);
	}
	return combo;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:29,代码来源:ParameterValueKeyCellEditor.java

示例12: createParameterCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
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;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:29,代码来源:ParameterValueKeyCellEditor.java

示例13: init

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * Test fails if it throws any exception.
 *
 * @throws Exception
 */
private void init() throws Exception {

    if (!System.getProperty("os.name").startsWith("Windows")) {
        System.out.println("This is Windows only test.");
        return;
    }

    final Frame frame = new Frame("AWT Frame");
    frame.pack();
    frame.setSize(200, 200);
    FramePeer frame_peer = AWTAccessor.getComponentAccessor()
                                .getPeer(frame);
    Class comp_peer_class
            = Class.forName("sun.awt.windows.WComponentPeer");
    Field hwnd_field = comp_peer_class.getDeclaredField("hwnd");
    hwnd_field.setAccessible(true);
    long hwnd = hwnd_field.getLong(frame_peer);

    Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame");
    Constructor constructor
            = clazz.getConstructor(new Class[]{long.class});
    final Frame embedded_frame
            = (Frame) constructor.newInstance(new Object[]{
                new Long(hwnd)});;
    final JComboBox<String> combo = new JComboBox<>(new String[]{
        "Item 1", "Item 2"
    });
    combo.setSelectedIndex(1);
    final Panel p = new Panel();
    p.setLayout(new BorderLayout());
    embedded_frame.add(p, BorderLayout.CENTER);
    embedded_frame.validate();
    p.add(combo);
    p.validate();
    frame.setVisible(true);
    Robot robot = new Robot();
    robot.delay(2000);
    Rectangle clos = new Rectangle(
            combo.getLocationOnScreen(), combo.getSize());
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height / 2);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (!combo.isPopupVisible()) {
        throw new RuntimeException("Combobox popup is not visible!");
    }
    robot.mouseMove(clos.x + clos.width / 2, clos.y + clos.height + 3);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(1000);
    if (combo.getSelectedIndex() != 0) {
        throw new RuntimeException("Combobox selection has not changed!");
    }
    embedded_frame.remove(p);
    embedded_frame.dispose();
    frame.dispose();

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:EmbeddedFrameGrabTest.java

示例14: addComboBox

import javax.swing.JComboBox; //导入方法依赖的package包/类
public JComboBox addComboBox(String name, String[] values, int initialRow) {
  JComboBox comboBox = new JComboBox(values);
  comboBox.setEditable(false);
  comboBox.setSelectedIndex(initialRow);

  addCtrl(name, comboBox);

  return comboBox;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:10,代码来源:PropertySheet.java

示例15: TransferDialog

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * Set up and show the dialog. The first Component argument determines which
 * frame the dialog depends on; it should be a component in the dialog's
 * controlling frame. The second Component argument should be null if you
 * want the dialog to come up with its left corner in the center of the
 * screen; otherwise, it should be the component on top of which the dialog
 * should appear.
 */

public TransferDialog(Component frameComp, Component locationComp,
		String title,  I_TickerManager tickerManager) {
	super(frameComp, locationComp, title, tickerManager);

	String[] currencies = {"EUR", "USD", "SEK" , "NOK"};
	currencyList = new JComboBox(currencies);
	currencyList.setEditable(true);
	currencyList.addActionListener(this);
	currencyList.setSelectedIndex(0);
	currencyList.setActionCommand(CURRENCY_CHANGED);
	
	totalCostField = new JTextField(FIELD_LEN);
	totalCostField.setEditable(true);
	totalCostField.setText("");		
	totalCostField.addKeyListener(this);
	
	dateFieldLabel = new JLabel("Maksupäivä: ");
	dateFieldLabel.setLabelFor(dateChooser);


	totalCostFieldLabel = new JLabel("yhteensä: ");
	totalCostFieldLabel.setLabelFor(totalCostField);

	currencyFieldLabel = new JLabel("Valuutta: ");
	
	updateRateFieldCcy((String) currencyList.getSelectedItem(), true);
	init(getDialogLabels(), getDialogComponents());
}
 
开发者ID:skarna1,项目名称:javaportfolio,代码行数:38,代码来源:TransferDialog.java


注:本文中的javax.swing.JComboBox.setSelectedIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。