Мне нужно иметь возможность выбирать каждую строку addDestinationNameAndPicture, чтобы настроить ее в области списка.
class TopDestinationListFrame extends JFrame {
private DefaultListModel listModel;
public TopDestinationListFrame() {
super("Top Five Destination List");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(900, 750);
listModel = new DefaultListModel();
//Make updates to your top 5 list below. Import the new image files to resources directory.
//added top 5 destinations and updated the pictures with the resources file.
addDestinationNameAndPicture("1. Moab, Utah (Red rocks, off-road, family fun.)", new ImageIcon(getClass().getResource("/resources/moab.jpeg")));
addDestinationNameAndPicture("2. Leavenworth, Washington (Charming Bavarian-themed village in the Cascade Mountains.)", new ImageIcon(getClass().getResource("/resources/leavenworth.jpeg")));
addDestinationNameAndPicture("3. Park City, Utah (Renowned ski resort town famous for its world class slopes.)", new ImageIcon(getClass().getResource("/resources/parkcity.jpeg")));
addDestinationNameAndPicture("4. Greenwater, Washington (Small, scenic mountain town located at the foothills of Mount Rainier.)", new ImageIcon(getClass().getResource("/resources/greenwater.jpeg")));
addDestinationNameAndPicture("5. San Diego, California (Coastal city known for its beautiful beaches, perfect weather and attractions.)", new ImageIcon(getClass().getResource("/resources/sandiego.jpeg")));
JList list = new JList(listModel);
JScrollPane scrollPane = new JScrollPane(list);
TextAndIconListCellRenderer renderer = new TextAndIconListCellRenderer();
list.setFont(new Font("Courier", Font.BOLD, 18));
list.setBackground(Color.lightGray);
list.setCellRenderer(renderer);
JLabel nameLabel = new JLabel("Developer: Haylee Raile");
getContentPane().add(nameLabel, BorderLayout.NORTH);
getContentPane().add(scrollPane, BorderLayout.CENTER);
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... llrenderer
Выбор отдельных элементов при использовании JList и setCellRenderer ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1731576730
Anonymous
Мне нужно иметь возможность выбирать каждую строку addDestinationNameAndPicture, чтобы настроить ее в области списка.
class TopDestinationListFrame extends JFrame {
private DefaultListModel listModel;
public TopDestinationListFrame() {
super("Top Five Destination List");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(900, 750);
listModel = new DefaultListModel();
//Make updates to your top 5 list below. Import the new image files to resources directory.
//added top 5 destinations and updated the pictures with the resources file.
addDestinationNameAndPicture("1. Moab, Utah (Red rocks, off-road, family fun.)", new ImageIcon(getClass().getResource("/resources/moab.jpeg")));
addDestinationNameAndPicture("2. Leavenworth, Washington (Charming Bavarian-themed village in the Cascade Mountains.)", new ImageIcon(getClass().getResource("/resources/leavenworth.jpeg")));
addDestinationNameAndPicture("3. Park City, Utah (Renowned ski resort town famous for its world class slopes.)", new ImageIcon(getClass().getResource("/resources/parkcity.jpeg")));
addDestinationNameAndPicture("4. Greenwater, Washington (Small, scenic mountain town located at the foothills of Mount Rainier.)", new ImageIcon(getClass().getResource("/resources/greenwater.jpeg")));
addDestinationNameAndPicture("5. San Diego, California (Coastal city known for its beautiful beaches, perfect weather and attractions.)", new ImageIcon(getClass().getResource("/resources/sandiego.jpeg")));
JList list = new JList(listModel);
JScrollPane scrollPane = new JScrollPane(list);
TextAndIconListCellRenderer renderer = new TextAndIconListCellRenderer();
list.setFont(new Font("Courier", Font.BOLD, 18));
list.setBackground(Color.lightGray);
list.setCellRenderer(renderer);
JLabel nameLabel = new JLabel("Developer: Haylee Raile");
getContentPane().add(nameLabel, BorderLayout.NORTH);
getContentPane().add(scrollPane, BorderLayout.CENTER);
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79186077/selecting-individual-items-when-using-jlist-and-setcellrenderer[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия