下面列出了javax.swing.JComboBox#setMaximumRowCount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private JComboBox<String> createPNGResolutionPopup() {
int selection = 0;
int resolution = Preferences.getInstance().getPNGResolution();
JComboBox<String> combo = new JComboBox<>();
setupCombo(combo, pngDPIMsg());
int length = DPI.length;
for (int i = 0; i < length; i++) {
combo.addItem(MessageFormat.format(I18n.Text("{0} dpi"), Integer.valueOf(DPI[i])));
if (DPI[i] == resolution) {
selection = i;
}
}
combo.setSelectedIndex(selection);
combo.addActionListener(this);
combo.setMaximumRowCount(combo.getItemCount());
UIUtilities.setToPreferredSizeOnly(combo);
return combo;
}
private static JComboBox<String> buildProductFormatNamesComboBox(Insets defaultListItemMargins, int textFieldPreferredHeight, String[] availableFormatNames) {
JComboBox<String> productFormatNameComboBox = new JComboBox<String>(availableFormatNames);
Dimension formatNameComboBoxSize = productFormatNameComboBox.getPreferredSize();
formatNameComboBoxSize.height = textFieldPreferredHeight;
productFormatNameComboBox.setPreferredSize(formatNameComboBoxSize);
productFormatNameComboBox.setMinimumSize(formatNameComboBoxSize);
LabelListCellRenderer<String> renderer = new LabelListCellRenderer<String>(defaultListItemMargins) {
@Override
protected String getItemDisplayText(String value) {
return value;
}
};
productFormatNameComboBox.setMaximumRowCount(5);
productFormatNameComboBox.setRenderer(renderer);
productFormatNameComboBox.setBackground(new Color(0, 0, 0, 0)); // set the transparent color
productFormatNameComboBox.setOpaque(true);
return productFormatNameComboBox;
}
protected void updateAnnotationSetsList() {
String corpusName =
(corpusToSearchIn.getSelectedItem()
.equals(Constants.ENTIRE_DATASTORE))
? null
: (String)corpusIds
.get(corpusToSearchIn.getSelectedIndex() - 1);
TreeSet<String> ts = new TreeSet<String>(stringCollator);
ts.addAll(getAnnotationSetNames(corpusName));
DefaultComboBoxModel<String> dcbm = new DefaultComboBoxModel<String>(ts.toArray(new String[ts.size()]));
dcbm.insertElementAt(Constants.ALL_SETS, 0);
annotationSetsToSearchIn.setModel(dcbm);
annotationSetsToSearchIn.setSelectedItem(Constants.ALL_SETS);
// used in the ConfigureStackViewFrame as Annotation type column
// cell editor
TreeSet<String> types = new TreeSet<String>(stringCollator);
types.addAll(getTypesAndFeatures(null, null).keySet());
// put all annotation types from the datastore
// combobox used as cell editor
JComboBox<String> annotTypesBox = new JComboBox<String>();
annotTypesBox.setMaximumRowCount(10);
annotTypesBox.setModel(new DefaultComboBoxModel<String>(types.toArray(new String[types.size()])));
DefaultCellEditor cellEditor = new DefaultCellEditor(annotTypesBox);
cellEditor.setClickCountToStart(0);
configureStackViewFrame.getTable().getColumnModel()
.getColumn(ANNOTATION_TYPE).setCellEditor(cellEditor);
}
private JComboBox<Object> createComboBox(Container parent, Object[] items, Object selection) {
JComboBox<Object> combo = new JComboBox<>(items);
combo.setSelectedItem(selection);
combo.addActionListener(this);
combo.setMaximumRowCount(items.length);
UIUtilities.setToPreferredSizeOnly(combo);
parent.add(combo);
return combo;
}
private JComboBox<Object> createComboBox(Container parent, Object[] items, Object selection, String tooltip) {
JComboBox<Object> combo = new JComboBox<>(items);
combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
combo.setSelectedItem(selection);
combo.addActionListener(this);
combo.setMaximumRowCount(items.length);
UIUtilities.setToPreferredSizeOnly(combo);
combo.setEnabled(mIsEditable);
parent.add(combo);
return combo;
}
private JComboBox<Object> createComboBox(Container parent, Object[] items, Object selection) {
JComboBox<Object> combo = new JComboBox<>(items);
combo.setSelectedItem(selection);
combo.addActionListener(this);
combo.setMaximumRowCount(items.length);
UIUtilities.setToPreferredSizeOnly(combo);
parent.add(combo);
return combo;
}
private <E> JComboBox<E> createCombo(JPanel panel, E[] values, E choice, String tooltip) {
JComboBox<E> combo = new JComboBox<>(values);
combo.setOpaque(false);
combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
combo.setSelectedItem(choice);
combo.addActionListener(this);
combo.setMaximumRowCount(combo.getItemCount());
UIUtilities.setToPreferredSizeOnly(combo);
panel.add(combo);
return combo;
}
/**
* Utility function to create a combobox, populate it, and set a few properties.
*
* @param parent Container for the widget.
* @param items Items of the combobox.
* @param selection The item initialliy selected.
* @param tooltip The tooltip of the combobox.
*/
protected <E> JComboBox<E> createComboBox(Container parent, E[] items, Object selection, String tooltip) {
JComboBox<E> combo = new JComboBox<>(items);
combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
combo.setSelectedItem(selection);
combo.addActionListener(this);
combo.setMaximumRowCount(items.length);
UIUtilities.setToPreferredSizeOnly(combo);
combo.setEnabled(mIsEditable);
parent.add(combo);
return combo;
}
/**
* Creates a new {@link JComboBox}.
*
* @param command The command to issue on selection.
* @param items The items to add to the {@link JComboBox}.
* @param selection The item to select initially.
* @return The new {@link JComboBox}.
*/
protected <T> JComboBox<T> addComboBox(String command, T[] items, T selection) {
JComboBox<T> combo = new JComboBox<>(items);
combo.setOpaque(false);
combo.setSelectedItem(selection);
combo.setActionCommand(command);
combo.addActionListener(this);
combo.setMaximumRowCount(items.length);
UIUtilities.setToPreferredSizeOnly(combo);
add(combo);
return combo;
}
private <E> JComboBox<E> createCombo(E[] values, E choice, String tooltip) {
JComboBox<E> combo = new JComboBox<>(values);
combo.setOpaque(false);
combo.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
combo.setSelectedItem(choice);
combo.addActionListener(this);
combo.setMaximumRowCount(combo.getItemCount());
UIUtilities.setToPreferredSizeOnly(combo);
add(combo);
return combo;
}
/**
* Creates a new instance of ExportDialog.
*
* @param creator
* The "creator" to be written into the header of the file (may
* be null)
* @param addAllExportFileTypes
* If true registers all the standard export filetypes
*/
public ExportDialog(String creator, boolean addAllExportFileTypes) {
super(null, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
this.creator = creator;
try {
baseDir = System.getProperty("user.home");
} catch (SecurityException x) {
trusted = false;
}
ButtonListener bl = new ButtonListener();
JPanel panel = new JPanel(new TableLayout());
if (trusted) {
panel.add("* * [5 5 5 5] w", file);
panel.add("* * * 1 [5 5 5 5] wh", browse);
}
type = new JComboBox(list);
type.setMaximumRowCount(16); // rather than 8
panel.add("* * 1 1 [5 5 5 5] w", type);
panel.add("* * * 1 [5 5 5 5] wh", advanced);
browse.addActionListener(bl);
advanced.addActionListener(bl);
type.setRenderer(new SaveAsRenderer());
type.addActionListener(bl);
setMessage(panel);
if (addAllExportFileTypes)
addAllExportFileTypes();
}
/**
* Creates and adds the token view combo box to the view
*
* @param toolBar the JToolBar to add the combo box to
* @param action the action that the tokenClassComboBox performs when selected
* @param view application view
*/
private void addTokenClassComboBox(JToolBar toolBar, Action action, PipeApplicationView view) {
String[] tokenClassChoices = new String[]{"Default"};
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(tokenClassChoices);
JComboBox<String> tokenClassComboBox = new JComboBox<>(model);
tokenClassComboBox.setEditable(true);
tokenClassComboBox.setSelectedItem(tokenClassChoices[0]);
tokenClassComboBox.setMaximumRowCount(100);
tokenClassComboBox.setEditable(false);
tokenClassComboBox.setAction(action);
view.register(tokenClassComboBox);
toolBar.add(tokenClassComboBox);
}
/**
* Adds a zoom combo box to the toolbar
*
* @param toolBar the JToolBar to add the button to
* @param action the action that the ZoomComboBox performs
* @param view application view
*/
private void addZoomComboBox(JToolBar toolBar, Action action, String[] zoomExamples, PipeApplicationView view) {
Dimension zoomComboBoxDimension = new Dimension(65, 28);
JComboBox<String> zoomComboBox = new JComboBox<>(zoomExamples);
zoomComboBox.setEditable(true);
zoomComboBox.setSelectedItem("100%");
zoomComboBox.setMaximumRowCount(zoomExamples.length);
zoomComboBox.setMaximumSize(zoomComboBoxDimension);
zoomComboBox.setMinimumSize(zoomComboBoxDimension);
zoomComboBox.setPreferredSize(zoomComboBoxDimension);
zoomComboBox.setAction(action);
view.registerZoom(zoomComboBox);
toolBar.add(zoomComboBox);
}
public JPanel buildStrategySelectionPanel(Window aParentContainer, Atdl4jOptions atdl4jOptions)
{
setAtdl4jOptions( atdl4jOptions );
JPanel panel = new JPanel(new BorderLayout());
// label
JLabel strategiesDropDownLabel = new JLabel("Strategy");
panel.add( strategiesDropDownLabel, BorderLayout.WEST );
// dropDownList
strategiesDropDown = new JComboBox();
strategiesDropDown.setEditable( false );
panel.add(strategiesDropDown, BorderLayout.CENTER);
if ( Atdl4jConfig.getConfig().getStrategyDropDownItemDepth() != null )
{
strategiesDropDown.setMaximumRowCount( Atdl4jConfig.getConfig().getStrategyDropDownItemDepth().intValue() );
}
// tooltip
strategiesDropDown.setToolTipText("Select a Strategy");
// action listener
strategiesDropDown.addItemListener( new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
firePreStrategySelectedEvent();
int index = strategiesDropDown.getSelectedIndex();
selectDropDownStrategy( index );
}
}
} );
return panel;
}