private void prepareTextComboBox(final Object propertyValue) { // _textComboBox wird in der letzten Zeile editierbar gemacht, und es wird // der übergebene Wert in diese Zeile eingetragen und selektiert, wenn er nicht // einem der anderen Einträge entspricht. if (propertyValue != null) { String propertyValueAsString = (String) propertyValue; final int size = _textComboBox.getModel().getSize(); boolean propertyValueFound = false; for (int i = 0; i < size - 1; i++) { if (propertyValueAsString.equals((String) _textComboBox.getItemAt(i))) { propertyValueFound = true; _textComboBox.setSelectedIndex(i); break; } } if (!propertyValueFound) { _textComboBox.removeItemAt(size - 1); _textComboBox.addItem(propertyValueAsString); _textComboBox.setSelectedIndex(size - 1); } } ItemListener textComboBoxItemListener = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (_textComboBox.getSelectedIndex() == DOTPointPainter.DYNAMIC_TEXT_ITEMS.length - 1) { _textComboBox.setEditable(true); } else { _textComboBox.setEditable(false); } } } }; _textComboBox.addItemListener(textComboBoxItemListener); ActionListener editorActionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { final int length = DOTPointPainter.DYNAMIC_TEXT_ITEMS.length; final int index = length - 1; final ComboBoxEditor editor = _textComboBox.getEditor(); String editedItem = (String) editor.getItem(); _textComboBox.insertItemAt(editedItem, index); final DefaultComboBoxModel model = (DefaultComboBoxModel) _textComboBox.getModel(); if (model.getSize() > length) { // Sieht komisch aus, aber der direkte Weg ging nicht. model.removeElementAt(length); } } }; _textComboBox.getEditor().addActionListener(editorActionListener); }
/* * Metodo eliminar() * sin parametros, sin retorno, elimina el elemento seleccionado del vector */ private void eliminar() { int seleccion = librosCombo.getSelectedIndex(); String nombre = librosCombo.getItemAt(seleccion).getAutorNombres() + " " + librosCombo.getItemAt(seleccion).getApellidosAutor(); int opcion = JOptionPane.showConfirmDialog( this, "Está seguro que desea borrar el registro del alumno\n" + nombre, "Eliminar Alumno", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (opcion == JOptionPane.YES_OPTION) { librosCombo.removeItemAt(seleccion); JOptionPane.showMessageDialog( this, "Registro eliminado con éxito", "Eliminar Alumno", JOptionPane.INFORMATION_MESSAGE); revisarCombo(); } }
private void initialize() { // throws Exception panel.setLayout(null); labelOriginal.setText(getString("LBL.SOURCE.FILE")); labelOriginal.setBounds(new Rectangle(5, 10, 200, 15)); fieldOriginal.setText(""); fieldOriginal.setBounds(new Rectangle(5, 30, 300, 22)); // _btnOriginal.setText( l10n( "BTN.BROWSE" ) ); setLocalizedText(buttonOriginal, getString("BTN.BROWSE.ORIGINAL")); buttonOriginal.addActionListener(this); buttonOriginal.setBounds(new Rectangle(310, 30, 100, 22)); // _btnTranslation.setText( l10n( "BTN.BROWSE" ) ); setLocalizedText(buttonTranslation, getString("BTN.BROWSE.TRANSLATION")); buttonTranslation.addActionListener(this); buttonTranslation.setEnabled(false); buttonTranslation.setBounds(new Rectangle(310, 75, 100, 22)); labelTranslation.setText(getString("LBL.TARGET.FILE")); labelTranslation.setBounds(new Rectangle(5, 55, 200, 15)); fieldTranslation.setText(""); fieldTranslation.setBounds(new Rectangle(5, 75, 300, 22)); setLocalizedText(buttonOk, getString("BTN.OK")); buttonOk.addActionListener(this); buttonOk.setBounds(new Rectangle(205, 115, 100, 22)); setLocalizedText(buttonCancel, getString("BTN.CANCEL")); buttonCancel.addActionListener(this); buttonCancel.setBounds(new Rectangle(310, 115, 100, 22)); addWindowListener( new WindowAdapter() { public void windowClosing(final WindowEvent evt) { onClose(); } }); setModal(true); setResizable(false); setTitle(getString("DLG.OPEN.TITLE")); getContentPane().setLayout(null); for (String item : idiom) { comboOriginalLang.addItem(item); comboTranslationLang.addItem(item); } comboOriginalLang.setToolTipText(getString("CB.LANG.SOURCE.TOOLTIP")); comboOriginalLang.setSelectedItem(Locale.getDefault().getDisplayLanguage()); comboOriginalLang.setBounds(new Rectangle(420, 30, 100, 22)); comboOriginalEncoding.removeItemAt(numEncodings - 1); comboOriginalEncoding.addItem(getString("ENCODING.DEFAULT")); comboOriginalEncoding.setToolTipText(getString("CB.ENCODING.TOOLTIP")); comboOriginalEncoding.setSelectedIndex(0); comboOriginalEncoding.setBounds(new Rectangle(530, 30, 100, 22)); labelOriginalLang.setText(getString("LBL.SOURCE.LANG")); labelOriginalLang.setBounds(new Rectangle(420, 10, 100, 16)); labelOriginalEncoding.setText(getString("LBL.ENCODING")); labelOriginalEncoding.setBounds(new Rectangle(530, 10, 100, 16)); comboTranslationLang.setToolTipText(getString("CB.LANG.TARGET.TOOLTIP")); comboTranslationLang.setSelectedItem(Locale.getDefault().getDisplayLanguage()); comboTranslationLang.setBounds(new Rectangle(420, 75, 100, 22)); comboTranslationLang.setEnabled(false); comboTranslationEncoding.removeItemAt(numEncodings - 1); comboTranslationEncoding.addItem(getString("ENCODING.DEFAULT")); comboTranslationEncoding.setToolTipText(getString("CB.ENCODING.TOOLTIP")); comboTranslationEncoding.setSelectedIndex(0); comboTranslationEncoding.setBounds(new Rectangle(530, 75, 100, 22)); comboTranslationEncoding.setEnabled(false); labelTranslation.setEnabled(false); labelTranslationLang.setText(getString("LBL.TARGET.LANG")); labelTranslationLang.setBounds(new Rectangle(420, 55, 100, 16)); labelTranslationLang.setEnabled(false); labelTranslationEncoding.setText(getString("LBL.ENCODING")); labelTranslationEncoding.setBounds(new Rectangle(530, 55, 100, 16)); panel.setBounds(new Rectangle(-1, 0, 640, 180)); panel.add(fieldTranslation, null); panel.add(fieldOriginal, null); panel.add(buttonOriginal, null); panel.add(buttonTranslation, null); panel.add(comboOriginalLang, null); panel.add(comboTranslationLang, null); panel.add(comboOriginalEncoding, null); panel.add(comboTranslationEncoding, null); panel.add(buttonCancel, null); panel.add(buttonOk, null); panel.add(labelOriginalLang, null); panel.add(labelOriginalEncoding, null); panel.add(labelTranslationEncoding, null); panel.add(labelOriginal, null); panel.add(labelTranslationLang, null); panel.add(labelTranslation, null); getContentPane().add(panel, null); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds((screenSize.width - 640) / 2, (screenSize.height - 180) / 2, 640, 180); }