Programming Examples

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

JSeparator & Control ToolTip

JSeparator and Tooltip Example

Here in this example, we have sample text boxes in the form. The JSeparator of Java Swing splits each of the text boxes. The splitter is in vertical orientation. Then, we will have tooltips for all the text fields in the window. In the above screen, the Data Of Birth text field is displaying the Tooltip for the user.

Continue Reading →

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 →

JViewport & Scroll View

JViewPort and Button Grid

The JViewport is like a porthole through which we can see a different position of the landscape. Using JViewport, one can change view position to see different portions of the document. It looks like document is moving, but java moves the view port to view view various document parts.

Here the document is the button grid. We almost display 5000 buttons on this grid. In the above screen, it is evident that the JFrame can show only first 130 buttons. The buttons, up and down in the bottom, perform upward and downward movement of the JViewPort there by viewing the other buttons in the Grid.

Continue Reading →