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

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 →

JTextPane & Text Formatting

Java Swing JTextPane Example

The example is a JFrame Window which houses a JTextPane. Here, one can see the JTextPane Example displaying the content with a mixture of texts and images. The document displays heading text in blue colour and normal text in red colour. The heading text is slightly bigger than the normal text. Towards the end of the document, there will be document footer in green colour. This is not shown above.

Using this example, we will learn how to insert text and image into the JTextPane. At this moment, we can also visualize that we have three variations of the text and, in this example, we will group three types of text formatting styles to prepare the document.

Continue Reading →

JRadioButton & ItemListener

JRadioButton Example

Our example shows three radio buttons in a form. A user can select any one of these radio buttons and only one radio button will be in the selected state. Above, the radio button three is in the selected state. When a radio button is in checked (selected) state, our example will flash a message box stating which radio button is in the selected state. Here in this example, we will create all these radio buttons using JRadioButton component of the Java Swing.

Continue Reading →