Доступный для редактирования JCombobox включил

Согласно Файл. Документация Delete, , необходимо будет разделить атрибут "только для чтения". Можно установить атрибуты файла с помощью Файл. SetAttributes () .

using System.IO;

File.SetAttributes(filePath, FileAttributes.Normal);
File.Delete(filePath);

10
задан Fortega 20 October 2009 в 12:15
поделиться

3 ответа

setEditable(boolean) determines if the JComboBox allows text entry in addition to selecting a value via pull-down.

setEnabled(boolean) determines if the JComboBox is able to be interacted with at all. If it is not enabled, it is displayed as grayed out.

A JComboBox can have any mix of these properties -

  • setEditable(true) + setEnabled(true) = JComboBox allows text input in addition to pull down values and user can interact with it.
  • setEditable(false) + setEnabled(true) = JComboBox only allows values from the pull down to be selected and user can interact with it.
  • setEditable(true) + setEnabled(false) = JComboBox allows text input in addition to pull down values but user cannot interact with it.
  • setEditable(false) + setEnabled(false) = JComboBox only allows values from the pull down to be selected and user cannot interact with it.

A situation where you may have a JComboBox with setEnabled(false) and setEditable(true) would be where you want a JComboBox that allows text input, but the form is in a state where the value of the JComboBox isn't applicable. You would usually have some action that would call setEnabled(true) on the JComboBox once it does become applicable.

For example, if you have something like a student housing form, there may be a question on the form like 'Do you need a parking space?' with a JCheckbox. There's a JComboBox for the brand of car and a JTextFied for the license plate number. You may have the JComboBox pre-populated with common car brands - Ford, Chevy, Toyota, Honda, etc. - but decide you also want to allow it to be editable in case someone owns something like a Lamborghini (and is staying in student housing - yeah, right...). The value for car brand and license plate number aren't needed unless the user selects the JCheckBox signifying that they need a parking space. You would add a listener to the JCheckBox that would call setEnabled(true) on the JComboBox and JTextField when it was selected, and setEnabled(false) when it wasn't.

22
ответ дан 3 December 2019 в 15:06
поделиться

Если вы вызываете setEditable (true) , текстовое поле JComboBox становится редактируемым, позволяя пользователю вводить текст с клавиатуры в дополнение к выбору элемента из списка.

Если вы вызываете setEnabled (false) , весь элемент управления отключается, что не позволяет пользователю вообще взаимодействовать с ним.

7
ответ дан 3 December 2019 в 15:06
поделиться

SetEnable () - включает поле со списком, чтобы можно было выбирать элементы.

SetEditable () - Определяет, доступно ли редактирование поля JComboBox.

1
ответ дан 3 December 2019 в 15:06
поделиться
Другие вопросы по тегам:

Похожие вопросы: