Skip to main content

Posts

Swing Tutorials: Custom JList 2

The previous tutorial on Custom JList here covers the creation of a simple JList displaying a list of countries. This tutorial introduces the implementation of a custom cell renderer to achieve pretty cool stuff with the JList. Here, the list of countries appear with not just their names, but also their flags. First, we begin by modifying the Country model. We add a variable to hold the name of the country's flag. The flag is added in the same package as the view class. package com. coolcodingtutorials . model ; /** * * @author jaletechs */ public class Country { private String name; private int id; public Country ( int id, String name) { this . name = name; this . id = id; } public String getName () { return name; } public void setName (String name) { this . name = name; } public int getId () { return id; } public void setId ( int id) { this . id = i...
Recent posts

Swing Tutorials: Custom JList

The JList is a cool swing component that is used to display a list. Unlike a drop down or a JComboBox in swing, a JList displays all of its items at once, allowing the user to scroll in the event that the other items are not visible on the screen. For good UI/UX sometimes, a JList is sometimes the perfect widget for displaying a list of items that could trigger some actions on the UI. So let's get down to it. First we create a custom object. We wish our JList to display a list of countries, so we create a country object as seen below: package com. coolcodingtutorials . model ; /** * * @author jaletechs */ public class Country { private String name; private int id; public Country ( int id, String name) { this . name = name; this . id = id; } public String getName () { return name; } public void setName (String name) { this . name = name; } public int getId () { return id; } public void setId ( int id) { thi...