Programming Examples

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


JSplitPane – Splitting the Components

JSplitPane Example

The example shows two JTextField controls. A JSplitPane splits these two text fields vertically by running a divider horizontally. You can see the divider with a pair of arrows on the left side. These arrows help to expand the component when clicked. For example, if you click the down-arrow, top text field expands and bottom text field holds only the minimal needed space. When you click the down-arrow again, the JSplitPane hides bottom text field and shows only the top text field. This aspect is called One-Click-Expandable.

We can also adjust the size of the component by manually moving the divider. Note, the split pane can divide the component horizontally as well. Now, we will create this example and learn about the JSplitPane and in the meantime, you can watch the below YouTube video to learn the basics.

Continue Reading →

JTabbedPane – Add Tabs Dynamically

JTabbed Pane Example

Marker 1 and 2 show the controls placed on a panel and the panel placed on the top portion of the Frame Window. The Marker 3 and 4 together form the JTabbedPane. Marker three shows three tabs: Person Name, Person Age and Education. This shows an idea of how we packed related information in a Tab. The above screen shows that the user is on the Person Name tab. To switch between the tabs, the user will click on the Tab Name.

Buttons Top, Bottom, Left and Right changes the tab placement. For example, if you click Left, the tabs will get arranged in the left edge of the Frame Window. The Radio buttons Scroll, and Wrap will decide how the JTabbedPane arranges the tabs when there is no space to fit-in the new tab.

Continue Reading →

JProgressBar – Long Running Task Progress


After the JLabel, we have a JProgressBar component which occupies the entire width of the Frame window. Towards the bottom we have a JButton which will increment the progress bar value on each click. The first checkbox will set the progress maximum to 500 when checked. Second check box will change the JProgressBar Color and the third one will set the progress label on the progress bar. So, to test how ProgressBar works, one can make the combination of the three check boxes and use the JButton to mimic the progress of the long running task.

Continue Reading →

Swing JComboBox & ItemListener

Java Swing - JComboBox Example

The example contains two JLabels, two JTextFields and a JComboBox. Note, the above screen shows Java Swing JComboBox as an editable type. When the user selects an item in the combo box, we show that in the first text box. We also show the past selected item in the Deselected JTextField. A combo box can show only one item once the drop-down is collapsed. So when the user picks an item, in combo box point of view, one item was selected by the user and one was de-selected (the previous one).

Continue Reading →