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


Java JComboBox.setRenderer方法代码示例

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


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

示例1: getPreferredSize

import javax.swing.JComboBox; //导入方法依赖的package包/类
public Dimension getPreferredSize() {
    Dimension dim = super.getPreferredSize();
    if (PREFERRED_HEIGHT == -1) {
        GenericToolbar tb = new GenericToolbar();
        tb.setBorder(getBorder());
        tb.setBorderPainted(isBorderPainted());
        tb.setRollover(isRollover());
        tb.setFloatable(isFloatable());
        Icon icon = Icons.getIcon(GeneralIcons.SAVE);
        tb.add(new JButton("Button", icon)); // NOI18N
        tb.add(new JToggleButton("Button", icon)); // NOI18N
        tb.add(new JTextField("Text")); // NOI18N
        JComboBox c = new JComboBox();
        c.setEditor(new BasicComboBoxEditor());
        c.setRenderer(new BasicComboBoxRenderer());
        tb.add(c);
        tb.addSeparator();
        PREFERRED_HEIGHT = tb.getSuperPreferredSize().height;
    }
    dim.height = getParent() instanceof JToolBar ? 1 :
                 Math.max(dim.height, PREFERRED_HEIGHT);
    return dim;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:GenericToolbar.java

示例2: getLabelComboBox

import javax.swing.JComboBox; //导入方法依赖的package包/类
/** Returns the combo box for the label in the given type graph. */
private JComboBox<TypeLabel> getLabelComboBox(TypeGraph typeGraph) {
    final JComboBox<TypeLabel> result = new JComboBox<>();
    result.setFocusable(false);
    result.setRenderer(new DefaultListCellRenderer() {
        @SuppressWarnings("rawtypes")
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index,
            boolean isSelected, boolean cellHasFocus) {
            if (value instanceof TypeLabel) {
                value = HTMLConverter.HTML_TAG.on(((TypeLabel) value).toLine().toHTMLString());
            }
            return super.getListCellRendererComponent(list,
                value,
                index,
                isSelected,
                cellHasFocus);
        }
    });
    for (TypeLabel label : sortLabels(typeGraph.getLabels())) {
        if (!label.isDataType() && label != TypeLabel.NODE) {
            result.addItem(label);
        }
    }
    return result;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:27,代码来源:FindReplaceDialog.java

示例3: getCellEditor

import javax.swing.JComboBox; //导入方法依赖的package包/类
@Override
public java.awt.Component getCellEditor(Object value) {
	JComboBox<Object> combo = new JComboBox<Object>(vals);
	combo.setRenderer(new OptionComboRenderer<V>(this));
	if (value == null)
		combo.setSelectedIndex(-1);
	else
		combo.setSelectedItem(value);
	return combo;
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:11,代码来源:Attributes.java

示例4: initCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void initCombo(JComboBox providerCombo) {
    
    DefaultComboBoxModel providers = new DefaultComboBoxModel();
    
    for(Provider each : providerSupplier.getSupportedProviders()){
       providers.addElement(each);
    }

    if (providers.getSize() == 0 && providerSupplier.supportsDefaultProvider()){
        providers.addElement(ProviderUtil.DEFAULT_PROVIDER);
    } 

    if (providers.getSize() == 0){
        providers.addElement(EMPTY);
    }
    
    providerCombo.setModel(providers);
    providerCombo.addItem(SEPARATOR);
    providerCombo.addItem(new NewPersistenceLibraryItem());
    providerCombo.addItem(new ManageLibrariesItem());
    providerCombo.setRenderer(new PersistenceProviderCellRenderer(getDefaultProvider(providers)));
    //select either default or first or preferred provider depending on project details
    int selectIndex = 0;
    if(providers.getSize()>1 && providers.getElementAt(0) instanceof Provider){
        String defProviderVersion = ProviderUtil.getVersion((Provider) providers.getElementAt(0));
        boolean specialCase = (Util.isJPAVersionSupported(project, Persistence.VERSION_2_0) || Util.isJPAVersionSupported(project, Persistence.VERSION_2_1)) && (defProviderVersion == null || defProviderVersion.equals(Persistence.VERSION_1_0));//jpa 2.0 is supported by default (or first) is jpa1.0 or udefined version provider
        if(specialCase){
            for (int i = 1; i<providers.getSize() ; i++){
                if(preferredProvider.equals(providers.getElementAt(i))){
                    selectIndex = i;
                    break;
                }
            }
        }
    }
    providerCombo.setSelectedIndex(selectIndex);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:PersistenceProviderComboboxHelper.java

示例5: addComboBox

import javax.swing.JComboBox; //导入方法依赖的package包/类
private <T> void addComboBox(JPanel panel, JComboBox<T> box,
                             String prefix, T value) {
    box.setRenderer(new EnumRenderer<T>(prefix));
    box.setSelectedItem(value);
    box.addItemListener(this);
    panel.add(Utility.localizedLabel(prefix + "label"));
    panel.add(box);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:9,代码来源:ConfirmDeclarationDialog.java

示例6: getTableCellEditor

import javax.swing.JComboBox; //导入方法依赖的package包/类
@Override
public TableCellEditor getTableCellEditor(Engine engine, AccessRules rules,
                                          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) {
        @Override
        public boolean stopCellEditing() {
            if (box.getSelectedItem() instanceof Color)
                return super.stopCellEditing();
            return false;
        }
    };
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:30,代码来源:ColorAttributePlugin.java

示例7: createComboBox

import javax.swing.JComboBox; //导入方法依赖的package包/类
private JComboBox createComboBox(CandidateDescription[] choices, CandidateDescription defaultValue, Font font, FocusListener listener ) {
    JComboBox combo = new JComboBox(choices);
    combo.setSelectedItem(defaultValue);
    combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
    combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
    combo.setOpaque(false);
    combo.setFont( font );
    combo.addFocusListener( listener );
    combo.setEnabled( choices.length > 1 );
    combo.setRenderer( new DelegatingRenderer(combo.getRenderer()));
    InputMap inputMap = combo.getInputMap( JComboBox.WHEN_FOCUSED );
    inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_SPACE, 0), "showPopup" ); //NOI18N
    combo.getActionMap().put( "showPopup", new TogglePopupAction() ); //NOI18N
    return combo;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:FixDuplicateImportStmts.java

示例8: DataComboBoxSupport

import javax.swing.JComboBox; //导入方法依赖的package包/类
/** Not private because used in tests. */
DataComboBoxSupport(JComboBox comboBox, DataComboBoxModel dataModel, boolean allowAdding) {
    this.dataModel = dataModel;
    this.allowAdding = allowAdding;
    
    comboBox.setEditable(false);

    comboBox.setModel(new ItemComboBoxModel());

    comboBox.setRenderer(new ItemListCellRenderer());
    comboBox.addActionListener(new ItemActionListener());
    comboBox.addPopupMenuListener(new ItemPopupMenuListener());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:DataComboBoxSupport.java

示例9: initializeCombo

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void initializeCombo() {
    boolean hasExistingRepositories = (existingRepositories != null)
                                      && (existingRepositories.length != 0);
    boolean hasBugtrackingConnectors = (bugtrackingConnectors != null)
                                       && (bugtrackingConnectors.length != 0);

    if (!hasExistingRepositories && !hasBugtrackingConnectors) {
        throw new IllegalStateException("No data for the combo-box."); //NOI18N
    }

    String newConnectionFormatString
                = (bugtrackingConnectorDisplayFormat != null)
                  ? bugtrackingConnectorDisplayFormat
                  : NbBundle.getMessage(
                            ComboItemsRenderer.class,
                            "NewBugtrackingRepositoryConnection");  //NOI18N

    combo = new JComboBox(joinArrays(existingRepositories,
                                     createRepositoryInfos(bugtrackingConnectors)));
    combo.setRenderer(new ComboItemsRenderer(combo.getRenderer(),
                                             newConnectionFormatString));
    //combo.setEditable(false);

    if (repoToPreselect != null) {
        combo.setSelectedItem(repoToPreselect);
    }
    itemSelected(combo.getSelectedItem());
    combo.addItemListener(this);
    combo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(RepositorySelectorBuilder.class, "RepositorySelectorBuilder.combo.accessibleDescription")); // NOI18N

    if (label != null) {
        bindLabelToCombo();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:RepositorySelectorBuilder.java

示例10: actionPerformed

import javax.swing.JComboBox; //导入方法依赖的package包/类
@Messages({
    "ProjectAssociationAction.open_some_projects=Open some projects to choose from.",
    "ProjectAssociationAction.title_select_project=Select Project",
    "ProjectAssociationAction.could_not_associate=Failed to record a Hudson job association.",
    "ProjectAssociationAction.could_not_dissociate=Failed to find the Hudson job association to be removed."
})
@Override public void actionPerformed(ActionEvent e) {
    if (alreadyAssociatedProject == null) {
        SortedSet<Project> projects = new TreeSet<Project>(ProjectRenderer.comparator());
        projects.addAll(Arrays.asList(OpenProjects.getDefault().getOpenProjects()));
        if (projects.isEmpty()) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(Bundle.ProjectAssociationAction_open_some_projects(), NotifyDescriptor.INFORMATION_MESSAGE));
            return;
        }
        JComboBox box = new JComboBox(new DefaultComboBoxModel(projects.toArray(new Project[projects.size()])));
        box.setRenderer(new ProjectRenderer());
        if (DialogDisplayer.getDefault().notify(new NotifyDescriptor(box, Bundle.ProjectAssociationAction_title_select_project(), NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.PLAIN_MESSAGE, null, null)) != NotifyDescriptor.OK_OPTION) {
            return;
        }
        if (!ProjectHudsonProvider.getDefault().recordAssociation((Project) box.getSelectedItem(), assoc)) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(Bundle.ProjectAssociationAction_could_not_associate(), NotifyDescriptor.WARNING_MESSAGE));
        }
    } else {
        if (!ProjectHudsonProvider.getDefault().recordAssociation(alreadyAssociatedProject, null)) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(Bundle.ProjectAssociationAction_could_not_dissociate(), NotifyDescriptor.WARNING_MESSAGE));
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ProjectAssociationAction.java

示例11: connect

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * Connects a combo box with the list of dbschemas in a project, making
 * the combo box display these dbschemas.
 */
public static void connect(JComboBox comboBox, DBSchemaFileList dbschemaFileList) {
    comboBox.setModel(new DBSchemaModel(dbschemaFileList));
    comboBox.setRenderer(new DBSchemaRenderer(comboBox));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:DBSchemaUISupport.java

示例12: PackageBrowser

import javax.swing.JComboBox; //导入方法依赖的package包/类
public PackageBrowser(JFrame frame, String title, boolean modal) {
  super(MainFrame.mainFrame,title, modal);

addWindowListener(WindowDisposer.getDisposer());
  addKeyListener(WindowDisposer.getDisposer()); 		

  ActionEventHandler actionEventH = new ActionEventHandler();
  LibComboActionEvnetHandler libComboHandler = new LibComboActionEvnetHandler();
  PackageListSelectionEventHandler packageListSelectionEventH = new PackageListSelectionEventHandler();
  ClassListSelectionEventHandler classListSelectionEventH = new ClassListSelectionEventHandler();
  TreeExpansionEventHandler treeExpansionEventH = new TreeExpansionEventHandler();

  tabbedPane = new JTabbedPane();

  //List view tab
  libListRenderer = new LibComboCellRenderer();
  packageListRenderer = new PackageListCellRenderer();
  classListRenderer = new ClassListCellRenderer();

  libraryCombo = new JComboBox();
  libraryCombo.setRenderer(libListRenderer);
  libraryCombo.addActionListener(libComboHandler);

  packageList = new JList();
  packageList.setCellRenderer(packageListRenderer);
  packageList.addListSelectionListener(packageListSelectionEventH);

  classList = new JList();
  classList.setCellRenderer(classListRenderer);
  classList.addListSelectionListener(classListSelectionEventH);

  listViewTab = new ListViewPanel(libraryCombo, packageList, classList);

  tabbedPane.addTab("ListView", listViewTab);
  tabbedPane.setTabPlacement(SwingConstants.TOP);
  tabbedPane.setSelectedIndex(0);

  tree = new JTree();
  tree.putClientProperty("JTree.lineStyle", "Angled");
  tree.addTreeExpansionListener(treeExpansionEventH);

  treeRenderer = new PackageBrowserTreeCellRenderer();
  tree.setCellRenderer(treeRenderer);

  //Tree view tab
  treeViewTab = new TreeViewPanel(tree);
  treeViewTab.setPackageBrowser(this);
  tabbedPane.addTab("TreeView", treeViewTab);

  //buttons panel
  selectBtn = new JButton("Select");
  selectBtn.setActionCommand("Select");
  selectBtn.addActionListener(actionEventH);
  selectBtn.setEnabled(true);

  cancelBtn = new JButton("Close");
  cancelBtn.setActionCommand("Close");
  cancelBtn.addActionListener(actionEventH);

  btnP = new JPanel();
  FlowLayout btnL = new FlowLayout();
  btnP.setLayout(btnL);

  btnP.add(selectBtn);
  btnP.add(cancelBtn);

  setFirstData();

  getContentPane().add(tabbedPane, BorderLayout.CENTER);
  getContentPane().add(btnP, BorderLayout.SOUTH);
  getContentPane().add(new JPanel(),BorderLayout.WEST);
  getContentPane().add(new JPanel(),BorderLayout.EAST);

  setSize(250,480);
  setLocation(150, 150);
  this.setResizable(false);
}
 
开发者ID:FJplant,项目名称:AntIDE,代码行数:78,代码来源:PackageBrowser.java

示例13: ImagedComboEditor

import javax.swing.JComboBox; //导入方法依赖的package包/类
/**
 * Creates a new ImagedComboEditor and sets renderer for comboBox.
 */
public ImagedComboEditor() {
	super(new JComboBox());
	combo = (JComboBox) super.getComponent();
	combo.setRenderer(new ComboImageRenderer());
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:9,代码来源:ImagedComboBoxCellEditorFactory.java

示例14: connect

import javax.swing.JComboBox; //导入方法依赖的package包/类
public static void connect(JComboBox comboBox, SourceGroup[] sourceGroups) {
    comboBox.setModel(new DefaultComboBoxModel(sourceGroups));
    comboBox.setRenderer(new SourceGroupRenderer());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:SourceGroupUISupport.java

示例15: initComponents

import javax.swing.JComboBox; //导入方法依赖的package包/类
private void initComponents() {
    setLayout(new BorderLayout(4, 0));
    setBorder(new EmptyBorder(0, 2, 0, 8));
    setOpaque(false);
    setFocusTraversalPolicyProvider(true);
    setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
        @Override
        public Component getDefaultComponent(Container aContainer) {
            if (!SwingUtilities.isEventDispatchThread()) {
                return null;
            }
            final EditorCookie ec = actionContext.lookup(
                    EditorCookie.class);
            if (ec != null) {
                JEditorPane[] panes = ec.getOpenedPanes();
                if (panes != null) {
                    for (JEditorPane pane : panes) {
                        if (pane.isShowing()) {
                            return pane;
                        }
                    }
                }
            }

            return null;
        }
   });

    combo = new JComboBox();
    combo.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            DatabaseConnection dbconn = (DatabaseConnection)combo.getSelectedItem();
            combo.setToolTipText(dbconn != null ? dbconn.getDisplayName() : null);
        }
    });
    combo.setOpaque(false);
    combo.setModel(new DefaultComboBoxModel(
            new String[] { NbBundle.getMessage(ToolbarPresenter.class, "ConnectionAction.ToolbarPresenter.LoadingConnections") }));

    combo.setRenderer(new DatabaseConnectionRenderer());
    String accessibleName = NbBundle.getMessage(ConnectionAction.class, "LBL_DatabaseConnection");
    combo.getAccessibleContext().setAccessibleName(accessibleName);
    combo.getAccessibleContext().setAccessibleDescription(accessibleName);
    combo.setPreferredSize (new Dimension (400, combo.getPreferredSize ().height));

    add(combo, BorderLayout.CENTER);

    comboLabel = new JLabel();
    Mnemonics.setLocalizedText(comboLabel, NbBundle.getMessage(ConnectionAction.class, "LBL_ConnectionAction"));
    comboLabel.setOpaque(false);
    comboLabel.setLabelFor(combo);
    add(comboLabel, BorderLayout.WEST);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:55,代码来源:ConnectionAction.java


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