Programming Examples

Are you a Programmer or Application Developer or a DBA? Take a cup of coffee, sit back and spend few minutes here :)

Tag Archive for ‘JScrollPane’

Swing JList With String Array

JList and ListSelectionEvent

In the top part of the JFrame, there is a JList which has scrolling enabled. It can show four items with no scrolling. But, to see other items scrolling is required. When the user selects an item, this sample shows that in a label. The label is next to the JList and the above screen not showing it as we have selected no item yet.

There is a set of controls below the JList which we can use to find a specific item in the JList. For example, the user can type Mango in the JTextField and click on the Find button. Our sample will search the item in JList and when it finds one, it highlights that item by selecting it. We will also scroll our list box to the selected item so that user does not need to scroll the List to see what item got selected. This is useful when the list is huge.

Continue Reading →

JScrollPane – Scrolling Text Grid Panel

Java Swing JScrollPane Example

Java Swing provides JScrollPane to give scrolling support for the lengthy documents. The document can be a text, html documents or it can be a set of controls arranged in a container.

This example uses a grid of 1000 text boxes. Since we cannot view all the text boxes in the frame window, we give this grid of text boxes to the JScrollPane. Swing’s Scroll Pane component provides vertical & horizontal scroll bars and, using those, the user can scroll the grid and view any text box in the grid. In our example, we number the text boxes in a sequential order.

Continue Reading →

JTextArea with Word & Line Wrap

About the JTextArea Example

The finished example is showing a JTextArea component. You can also see how it is showing the multi-line text in it. Here in the above picture, complete text content is not visible in the component. But, the component has a scroll bar which we can scroll to view the remaining content. Our finished example display only the vertical scroll bar and when we progress through the example, we will see how to provide the horizontal scroll bar as well

Continue Reading →