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


Java JComboBox.getSelectedIndex方法代码示例

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


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

示例1: setFilterResultItem

import javax.swing.JComboBox; //导入方法依赖的package包/类
/** Adds or removes an item for {@link Filter#RESULT} to the filter chooser. */
private void setFilterResultItem(boolean hasResults) {
    JComboBox<Filter> chooser = getFilterChooser();
    if (hasResults != (chooser.getItemCount() == Filter.values().length)) {
        this.filterListening = false;
        boolean resultSelected = chooser.getSelectedIndex() == Filter.RESULT.ordinal();
        if (hasResults) {
            chooser.addItem(Filter.RESULT);
        } else {
            chooser.removeItemAt(Filter.RESULT.ordinal());
        }
        if (resultSelected) {
            chooser.setSelectedIndex(Filter.NONE.ordinal());
        }
        getJGraph().setFilter(Filter.NONE);
        this.filterListening = true;
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:19,代码来源:LTSDisplay.java

示例2: 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

示例3: algAttackChanged

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void algAttackChanged() {
	JComboBox<String> jCB = jwtST.getNoneAttackComboBox();
	switch (jCB.getSelectedIndex()) {
	default:
	case 0:
		algAttackMode = null;
		break;
	case 1:
		algAttackMode = "none";
		break;
	case 2:
		algAttackMode = "None";
		break;
	case 3:
		algAttackMode = "nOnE";
		break;
	case 4:
		algAttackMode = "NONE";
		break;
	}
}
 
开发者ID:mvetsch,项目名称:JWT4B,代码行数:22,代码来源:JWTInterceptTabController.java

示例4: getDupAction

import javax.swing.JComboBox; //导入方法依赖的package包/类
int getDupAction(String url) {
	JTextField txt = new JTextField(url, 30);
	String lbl = StringResource.getString("DUP_TXT");
	JComboBox choice = new JComboBox(new String[] { StringResource.getString("DUP_OP1"),
			StringResource.getString("DUP_OP2"), StringResource.getString("DUP_OP3") });
	JCheckBox chk = new JCheckBox(StringResource.getString("DUP_CHK"));
	int ret = JOptionPane.showOptionDialog(null, new Object[] { txt, lbl, choice, chk },
			StringResource.getString("DUP_TITLE"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null,
			null, null);
	if (ret == JOptionPane.OK_OPTION) {
		int index = choice.getSelectedIndex();
		if (chk.isSelected()) {
			config.duplicateLinkAction = index;
		}
		return index;
	}
	return -1;
}
 
开发者ID:kmarius,项目名称:xdman,代码行数:19,代码来源:XDMMainWindow.java

示例5: getColor

import javax.swing.JComboBox; //导入方法依赖的package包/类
static Color getColor (JComboBox<ColorValue> combo) {
    // The last item is Inherited Color or None
    if (combo.getSelectedIndex() < combo.getItemCount() - 1) {
        return ((ColorValue) combo.getSelectedItem()).color;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ColorComboBox.java

示例6: getSelectedItemText

import javax.swing.JComboBox; //导入方法依赖的package包/类
public static String getSelectedItemText(JComboBox combo) {
    int selectedIndex = combo.getSelectedIndex();
    if (selectedIndex == -1) {
        return "";
    }
    return JComboBoxOptionJavaElement.getText(combo, selectedIndex, true);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:8,代码来源:JComboBoxJavaElement.java

示例7: 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

示例8: actionPerformed

import javax.swing.JComboBox; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
    if (ignoreComboAction)
        return; // not invoked by user, ignore

    GuardedBlock gBlock = codeData.getGuardedBlock(category, blockIndex);
    GuardBlockInfo gInfo = getGuardInfos(category)[blockIndex];
    int[] blockBounds = getGuardBlockBounds(category, blockIndex);
    int startOffset = blockBounds[0];
    int endOffset = blockBounds[1];
    int gHead = gBlock.getHeaderLength();
    int gFoot = gBlock.getFooterLength();
    JTextComponent editor = getEditor(category);
    StyledDocument doc = (StyledDocument) editor.getDocument();

    changed = true;

    JComboBox combo = (JComboBox) e.getSource();
    try {
        docListener.setActive(false);
        if (combo.getSelectedIndex() == 1) { // changing from default to custom
            NbDocument.unmarkGuarded(doc, startOffset, endOffset - startOffset);
            // keep last '\n' so we don't destroy next editable block's position
            doc.remove(startOffset, endOffset - startOffset - 1);
            // insert the custom code into the document
            String customCode = gBlock.getCustomCode();
            int customLength = customCode.length();
            if (gInfo.customizedCode != null) { // already was edited before
                customCode = customCode.substring(0, gHead)
                             + gInfo.customizedCode
                             + customCode.substring(customLength - gFoot);
                customLength = customCode.length();
            }
            if (customCode.endsWith("\n")) // NOI18N
                customCode = customCode.substring(0, customLength-1);
            doc.insertString(startOffset, customCode, null);
            gInfo.customized = true;
            // make guarded "header" and "footer", select the text in between
            NbDocument.markGuarded(doc, startOffset, gHead);
            NbDocument.markGuarded(doc, startOffset + customLength - gFoot, gFoot);
            editor.setSelectionStart(startOffset + gHead);
            editor.setSelectionEnd(startOffset + customLength - gFoot);
            editor.requestFocus();
            combo.setToolTipText(gBlock.getCustomEntry().getToolTipText());
        }
        else { // changing from custom to default
            // remember the customized code
            gInfo.customizedCode = doc.getText(startOffset + gHead,
                                               endOffset - gFoot - gHead - startOffset);
            NbDocument.unmarkGuarded(doc, endOffset - gFoot, gFoot);
            NbDocument.unmarkGuarded(doc, startOffset, gHead);
            // keep last '\n' so we don't destroy next editable block's position
            doc.remove(startOffset, endOffset - startOffset - 1);
            String defaultCode = gBlock.getDefaultCode();
            if (defaultCode.endsWith("\n")) // NOI18N
                defaultCode = defaultCode.substring(0, defaultCode.length()-1);
            doc.insertString(startOffset, defaultCode, null);
            gInfo.customized = false;
            // make the whole text guarded, cancel selection
            NbDocument.markGuarded(doc, startOffset, defaultCode.length()+1); // including '\n'
            if (editor.getSelectionStart() >= startOffset && editor.getSelectionEnd() <= endOffset)
                editor.setCaretPosition(startOffset);
            combo.setToolTipText(NbBundle.getMessage(CustomCodeData.class, "CTL_GuardCombo_Default_Hint")); // NOI18N
        }
        // we must create a new Position - current was moved away by inserting new string on it
        gInfo.position = NbDocument.createPosition(doc, startOffset, Position.Bias.Forward);

        docListener.setActive(true);
    }
    catch (BadLocationException ex) { // should not happen
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:74,代码来源:CustomCodeView.java

示例9: actionPerformed

import javax.swing.JComboBox; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e)
{
    JComboBox cb = (JComboBox)e.getSource();
    graph_index = cb.getSelectedIndex();
    layout_combo.setSelectedIndex(layout_combo.getSelectedIndex()); // rebuild the layout
}
 
开发者ID:dev-cuttlefish,项目名称:cuttlefish,代码行数:7,代码来源:ShowLayouts.java


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