Programming Examples

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

Swing

JFileChooser – Get Full File Path

JFileChooser Selected File Example

When we launch the example, it will display a frame window with text field. The click of the ellipsis button (…) will open the file open dialog. From the displayed dialog, we can browse through the folders of the PC and pick a specific file on the folder structure. Our example will display the selected file in the text field. This happens only when the user clicks the Open button. When the user clicks the Cancel button, it will not show the picked file in the text field.

Continue Reading →

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 →