Мне нужно иметь возможность выбирать каждую строку 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 JList сообщает о неправильном индексе при использовании KeyListener
Anonymous » » в форуме JAVA - 0 Ответы
- 16 Просмотры
-
Последнее сообщение Anonymous
-