JAVA JLIST TUTORIAL PDF

JList is a Swing component with which we can display a list of elements. This component also allows the user to select one or more elements visually. This article shows how to work with JList and proceeds to show some examples. We will write code to achieve a JList output like:. Developing A Simple JList. Adding a Scrollpane.

Author:Kigalar Vulkree
Country:Cuba
Language:English (Spanish)
Genre:Finance
Published (Last):22 October 2017
Pages:472
PDF File Size:10.62 Mb
ePub File Size:19.55 Mb
ISBN:188-8-72068-457-9
Downloads:18169
Price:Free* [*Free Regsitration Required]
Uploader:Faugal



The class JList is a component which displays a list of objects and allows the user to select one or more items. A separate model, ListModel, maintains the contents of the list. Adds a listener to the list, to be notified each time a change to the selection occurs; the preferred way of listening for selection state changes.

Returns an instance of DefaultListSelectionModel; called during construction to initialize the list's selection model property. Notifies ListSelectionListeners added directly to the list of selection changes made to the selection model.

Returns the bounding rectangle, in the list's coordinate system, for the range of cells specified by the two indices. Returns the location that this component should visually indicate as the drop location during a DnD operation over the component, or null if no location is to currently be shown.

Returns the "prototypical" cell value -- a value used to calculate a fixed width and height for cells. Returns the distance to scroll to expose the next or previous row for vertical scrolling or column for horizontal scrolling. Returns the smallest selected cell index; the selection when only a single item is selected in the list.

Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list. Returns an array of all the selected values, in an increasing order based on their indices in the list. ListUI class that defines the look and feel for this component. Sets the model that represents the contents or "value" of the list, notifies property change listeners, and then clears the list's selection.

Sets the prototypeCellValue property, and then if the new value is non-null , computes the fixedCellWidth and fixedCellHeight properties by requesting the cell renderer component for the given value and index 0 from the cell renderer, and using that component's preferred size.

Sets the color used to draw the background of the selected items, which cell renderers can use to fill the selected cells. Sets the color used to draw the foreground of the selected items, which cell renderers can use to render text and graphics. Sets the visibleRowCount property, which has different meanings depending on the layout orientation: For a VERTICAL layout orientation, this sets the preferred number of rows to display without requiring scrolling; for other orientations, it affects the wrapping of cells.

Compile the program using the command prompt. If no error occurs, it means the compilation is successful. Run the program using the following command. Previous Page. Next Page. DropLocation getDropLocation Returns the location that this component should visually indicate as the drop location during a DnD operation over the component, or null if no location is to currently be shown.

Bias bias Returns the next list element whose toString value starts with the given prefix. Previous Page Print Page. Rectangle getCellBounds int index0, int index1 Returns the bounding rectangle, in the list's coordinate system, for the range of cells specified by the two indices. ListModel getModel Returns the data model that holds the list of items displayed by the JList component. Object getPrototypeCellValue Returns the "prototypical" cell value -- a value used to calculate a fixed width and height for cells.

Object getSelectedValue Returns the value for the smallest selected cell index; the selected value when only a single item is selected in the list.

Object[] getSelectedValues Returns an array of all the selected values, in an increasing order based on their indices in the list. Color getSelectionBackground Returns the color used to draw the background of selected items. Color getSelectionForeground Returns the color used to draw the foreground of selected items. Point indexToLocation int index Returns the origin of the specified item in the list's coordinate system.

LEI 12593 PDF

SWING - JList Class

Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. A JList presents the user with a group of items, displayed in one or more columns, to choose from. Lists can have many items, so they are often put in scroll panes. In addition to lists, the following Swing components present multiple selectable items to the user: combo boxes , menus , tables , and groups of check boxes or radio buttons.

DATASHEET 2SA1015 PDF

Java JList

.

Related Articles