Programming Examples

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


Articles on Java programming language.

JavaFx Default & Cancel Buttons

Fig 3. JavaFx Button Example

In the JavaFx framework, buttons play a crucial role in facilitating user interaction and triggering specific actions. Typically, users manipulate buttons by positioning their mouse cursor over them and clicking to initiate a desired action. It’s worth noting that a single container can contain multiple buttons, among which there can be a designated Default Button and a Cancel button. Upon pressing the Enter key on the keyboard, the default button’s handler is invoked, while pressing the Esc key

Continue Reading →

JavaFx Label with Mnemonic

Fig 1. JavaFx Label Control Mnemonic

A Label can be placed before the other UI node or on top of the UI node. A Label cannot be focused on. This means, we cannot use the Tab key to set the focus to a Label. Even though it will not receive focus, it can transfer the focus to other controls and in this example, we will set Mnemonic to a label control so that it will transfer the focus to another control.

Continue Reading →

JavaFx CSS Style Example

Fig 1. About JavaFx CSS Example

In JavaFx, we can apply CSS style to the nodes. For example, if we want to define a style for the buttons, the style sheet will have the selector named as ‘.button’. The same way, TextField defines a UI class in JavaFx, and the selector will be named as ‘.text-field’. Note, as text field control is a two-word class, in the selector we will have a hyphen. When defining the rules, we must prefix each rule with ‘-fx-‘. In this example, we will define style rule for a JavaFx Button.

Continue Reading →

JavaFx LinearGradient Examples

Fig 3. Changing the Gradient Axis in JavaFx Gradient Fill

The LinearGradient class helps in applying such a gradient to any JavaFx shapes. In JavaFx, Linear Colour Gradient is applied by an axis in which a colour changes gradually from one point to another point. We call this axis as Gradient Axis. If we draw a line perpendicular to a specific point in the linear gradient axis, all the pixels in the perpendicular axis represents same colour.

Continue Reading →

JavaFx Pattern Fill Shapes

Fig 7 - Setting the proportional to false

JavaFx allows filling the closed shapes with a color. It is also possible to create an image and use it to fill the closed shapes. JavaFx provides the ImagePattern class which defines how the image pattern paints the target 2d shape. The ImagePattern class needs an Image object and fill rectangle (also called as Anchor Rectangle) definition. In this example, we will explore the ImagePattern class and fill the shapes rectangle and circle.

Continue Reading →