Java Code Examples for javax.swing.JComboBox#setPrototypeDisplayValue()
The following examples show how to use
javax.swing.JComboBox#setPrototypeDisplayValue() .
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: FindDialog.java From FancyBing with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") private JPanel createInputPanel() { JPanel outerPanel = new JPanel(new BorderLayout()); JPanel innerPanel = new JPanel(new BorderLayout()); m_comboBox = new JComboBox(getHistory().toArray()); StringBuilder prototype = new StringBuilder(70); for (int i = 0; i < 40; ++i) prototype.append('-'); m_comboBox.setPrototypeDisplayValue(prototype.toString()); m_comboBox.setEditable(true); ComboBoxEditor editor = m_comboBox.getEditor(); m_comboBox.addActionListener(this); m_textField = (JTextField)editor.getEditorComponent(); m_textField.selectAll(); KeyListener keyListener = new KeyAdapter() { public void keyPressed(KeyEvent e) { int c = e.getKeyCode(); if (c == KeyEvent.VK_ESCAPE && ! m_comboBox.isPopupVisible()) dispose(); } }; m_textField.addKeyListener(keyListener); GuiUtil.setMonospacedFont(m_comboBox); innerPanel.add(m_comboBox, BorderLayout.CENTER); outerPanel.add(innerPanel, BorderLayout.NORTH); return outerPanel; }
Example 2
Source File: FormUtils.java From jdal with Apache License 2.0 | 5 votes |
public static JComboBox<?> newCombo(int chars) { StringBuilder sb = new StringBuilder(chars); while (chars-- > 0) sb.append("X"); JComboBox<String> combo = new JComboBox<String>(); combo.setPrototypeDisplayValue(sb.toString()); return combo; }
Example 3
Source File: ComboPopupPrototype.java From radiance with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Creates the main frame for <code>this</code> sample. */ public ComboPopupPrototype() { super("Combo popup prototype"); this.setLayout(new GridLayout(1, 3)); JPanel panel1 = new JPanel(new FlowLayout()); JComboBox<String> comboProto1 = new JComboBox<>(new String[] { "aa", "aaaaa", "aaaaaaaaaa", "this one is the one", "abcdefghijklmnopqrstuvwxyz" }); comboProto1.setPrototypeDisplayValue("aaaaa"); // set popup prototype as hard-code value in the model SubstanceCortex.ComponentScope.setComboBoxPrototypeDisplayValue(comboProto1, "this one is the one"); panel1.add(new JLabel("Hard-coded value")); panel1.add(comboProto1); this.add(panel1); JPanel panel2 = new JPanel(new FlowLayout()); JComboBox<String> comboProto2 = new JComboBox<>(new String[] { "aa", "aaaaa", "aaaaaaaaaa", "another one (not it)", "abcdefghijklmnopqrstuvwxyz" }); comboProto2.setPrototypeDisplayValue("aaaaa"); // set popup prototype as widest value (core implementation of // ComboPopupPrototypeCallback interface) SubstanceCortex.ComponentScope.setComboBoxPrototypeCallback(comboProto2, new WidestComboPopupPrototype<String>()); panel2.add(new JLabel("Widest core callback")); panel2.add(comboProto2); this.add(panel2); JPanel panel3 = new JPanel(new FlowLayout()); JComboBox<String> comboProto3 = new JComboBox<>(new String[] { "aa", "aaaaa", "this is not", "this one is not it", "this one is it that is for the popup" }); comboProto3.setPrototypeDisplayValue("aaaaa"); // set popup prototype as custom implementation of // ComboPopupPrototypeCallback interface SubstanceCortex.ComponentScope.setComboBoxPrototypeDisplayValue(comboProto3, (ComboPopupPrototypeCallback<String>) jc -> jc.getModel().getElementAt(jc.getModel().getSize() - 1)); panel3.add(new JLabel("Custom callback")); panel3.add(comboProto3); this.add(panel3); this.setSize(400, 200); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
Example 4
Source File: MainForm.java From zxpoly with GNU General Public License v3.0 | 4 votes |
private Optional<SourceSoundPort> showSelectSoundLineDialog( final List<SourceSoundPort> variants) { assertUiThread(); final JPanel panel = new JPanel(new FlowLayout(FlowLayout.TRAILING)); final String previouslySelectedDevice = AppOptions.getInstance().getLastSelectedAudioDevice(); final JComboBox<SourceSoundPort> comboBox = new JComboBox<>(variants.toArray(new SourceSoundPort[0])); comboBox.setPrototypeDisplayValue( new SourceSoundPort(null, "some very long device name to be shown", null)); comboBox.addActionListener(x -> { comboBox.setToolTipText(comboBox.getSelectedItem().toString()); }); comboBox.setToolTipText(comboBox.getSelectedItem().toString()); int index = -1; for (int i = 0; i < comboBox.getItemCount(); i++) { if (comboBox.getItemAt(i).toString().equals(previouslySelectedDevice)) { index = i; break; } } comboBox.setSelectedIndex(Math.max(0, index)); panel.add(new JLabel("Sound device:")); panel.add(comboBox); if (JOptionPane.showConfirmDialog( this, panel, "Select sound device", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE ) == JOptionPane.OK_OPTION) { final SourceSoundPort selected = (SourceSoundPort) comboBox.getSelectedItem(); AppOptions.getInstance().setLastSelectedAudioDevice(selected.toString()); return Optional.ofNullable(selected); } else { return Optional.empty(); } }
Example 5
Source File: ReprojectionForm.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private JPanel createOuputSettingsPanel() { final TableLayout tableLayout = new TableLayout(3); tableLayout.setTableAnchor(TableLayout.Anchor.WEST); tableLayout.setTableFill(TableLayout.Fill.HORIZONTAL); tableLayout.setColumnFill(0, TableLayout.Fill.NONE); tableLayout.setTablePadding(4, 4); tableLayout.setColumnPadding(0, new Insets(4, 4, 4, 20)); tableLayout.setColumnWeightX(0, 0.0); tableLayout.setColumnWeightX(1, 0.0); tableLayout.setColumnWeightX(2, 1.0); tableLayout.setCellColspan(0, 1, 2); tableLayout.setCellPadding(1, 0, new Insets(4, 24, 4, 20)); final JPanel outputSettingsPanel = new JPanel(tableLayout); outputSettingsPanel.setBorder(BorderFactory.createTitledBorder("Output Settings")); final BindingContext context = new BindingContext(reprojectionContainer); final JCheckBox preserveResolutionCheckBox = new JCheckBox("Preserve resolution"); context.bind(Model.PRESERVE_RESOLUTION, preserveResolutionCheckBox); collocationCrsUI.getCrsUI().addPropertyChangeListener("collocate", evt -> { final boolean collocate = (Boolean) evt.getNewValue(); reprojectionContainer.setValue(Model.PRESERVE_RESOLUTION, collocate || reprojectionModel.preserveResolution); preserveResolutionCheckBox.setEnabled(!collocate); }); outputSettingsPanel.add(preserveResolutionCheckBox); JCheckBox includeTPcheck = new JCheckBox("Reproject tie-point grids", true); context.bind(Model.REPROJ_TIEPOINTS, includeTPcheck); outputSettingsPanel.add(includeTPcheck); outputParamButton = new JButton("Output Parameters..."); outputParamButton.setEnabled(!reprojectionModel.preserveResolution); outputParamButton.addActionListener(new OutputParamActionListener()); outputSettingsPanel.add(outputParamButton); outputSettingsPanel.add(new JLabel("No-data value:")); final JTextField noDataField = new JTextField(); outputSettingsPanel.add(noDataField); context.bind(Model.NO_DATA_VALUE, noDataField); JCheckBox addDeltaBandsChecker = new JCheckBox("Add delta lat/lon bands"); outputSettingsPanel.add(addDeltaBandsChecker); context.bind(Model.ADD_DELTA_BANDS, addDeltaBandsChecker); outputSettingsPanel.add(new JLabel("Resampling method:")); JComboBox<String> resampleComboBox = new JComboBox<>(RESAMPLING_IDENTIFIER); resampleComboBox.setPrototypeDisplayValue(RESAMPLING_IDENTIFIER[0]); context.bind(Model.RESAMPLING_NAME, resampleComboBox); outputSettingsPanel.add(resampleComboBox); reprojectionContainer.addPropertyChangeListener(Model.PRESERVE_RESOLUTION, evt -> updateOutputParameterState()); return outputSettingsPanel; }