Found 155 Articles for JavaFX

How to toggle menu items in JavaFX?

Maruthi Krishna
Updated on 20-May-2020 06:59:42

487 Views

JavaFX supports three kinds of menu items namely − check menu item, custom menu item, and, radio menu item.A RadioMenuItem is a special MenuItem that has a checkmark (tick) similar to a checkbox. This has two states selected (with a checkmark) and unselected (without checkmark). It is represented by the javafx.scene.control.RadioMenuItem class.You can add a bunch of radio-menu-items to a toggle group just like a toggle button or a radio button.ExampleFollowing JavaFX example demonstrates the creation of a toggled group of radio-menu-itemsimport javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Menu; import javafx.scene.control.MenuBar; import javafx.scene.control.MenuItem; import javafx.scene.control.RadioMenuItem; import javafx.scene.control.SeparatorMenuItem; import javafx.scene.control.ToggleGroup; import ... Read More

How to embed nodes in a JavaFX MenuItem?

Maruthi Krishna
Updated on 20-May-2020 06:57:39

153 Views

A menu is a list of options or commands presented to the user. In JavaFX a menu is represented by the javafx.scene.control.Menu class, you can create a menu by instantiating this class.A menu item is an option in the menu it is represented by the javafx.scene.control.MenuItem class, a superclass of the Menu class. You can display a text or a graphic as a menu item and add the desired cation to it.Setting a node as a menu itemThe MenuItem class has a property named graphic this is of the type Node; this specifies the optional graphic for the current menu-item. ... Read More

How to make the labels of a JavaFX Pie chart invisible?

Maruthi Krishna
Updated on 20-May-2020 06:55:30

369 Views

In the pie chart, we represent the data values as slices of a circle. Each slice is differentiated from other (typically by color). In JavaFX, you can create a pie chart by instantiating the javafx.scene.chart.PieChart class.Making Labels InvisibleEach slice is associated with a label. (name of the slice as value) By default, these labels are visible. This class has a property named labels visible specifying whether to display the labels in the pie chart or not. You can set the value to this property using the setLabelsVisible() method.To make the labels of the current pie chart invisible you need to ... Read More

JavaFX example to add a tooltip to a radio button

Maruthi Krishna
Updated on 20-May-2020 06:53:15

252 Views

Radio ButtonA radio button is a type of button, which is circular in shape. It has two states, selected and deselected. Generally, radio buttons are grouped using toggle groups, where you can only select one of them. You can create a radio button in JavaFX by instantiating the javafx.scene.control.RadioButton class.TooltipWhenever you hover over the mouse pointer over an element (say, button, label, etc..) in your application, the tooltip displays a hint about it. In JavaFX the tooltip is represented by the javafx.scene.control.Tooltip class, you can create a tooltip by instantiating it.While instantiating the class you need to pass the text ... Read More

How can we prevent the resizing of UI controls in JavaFX?

Maruthi Krishna
Updated on 20-May-2020 06:51:15

1K+ Views

In JavaFX the javafx.scene.control package provides various classes for nodes specially designed for UI applications by instantiating these classes you can create UI elements such as button, Label, etc..You can resize the created elements using the setPrefWidth() or, setPrefHeight() or, setprefSize() methods accordingly.To prevent the resize of the UI controls you need to set the minimum-maximum and preferred width/height to same value as −button.setMinWidth(80.0); button.setPrefWidth(80.0); button.setMaxWidth(80.0);ExampleThe following JavaFX example contains two buttons and a slider. You can resize the button (Hello) by moving the slider. Once you click the PreventResizing button, then you cannot resize the “Hello” button further.import javafx.application.Application; ... Read More

How to change the orientation of nodes in a tile pane using JavaFX?

Maruthi Krishna
Updated on 20-May-2020 06:48:15

171 Views

In the TilePane layout, the nodes are arranged as a grid of uniformly sized tiles. You can create a tile pane in your application by instantiating the javafx.scene.layout.TilePane class.Orientation refers to the arrangement of the nodes in the pane in general, they are arranged wither horizontally or vertically.By default the orientation of the tile pane is horizontal. You can change this using the setOrientation() method. This method accepts two values −Orientation.VERTICALOrientation.HORIZONTALExampleimport javafx.application.Application; import javafx.collections.ObservableList; import javafx.geometry.Orientation; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.TilePane; import javafx.stage.Stage; public class TilePaneOrientation extends Application {    @Override    public void start(Stage stage) { ... Read More

How to add multiple LineCharts into one Scene/Stage in JavaFX?

Maruthi Krishna
Updated on 20-May-2020 06:45:06

283 Views

You can create a line chart by instantiating the javafx.scene.chart.LineChart class. Following is an example to create multiple line charts in a single JavaFX window. Here, we are plotting the average temperatures of three different cities in a year.In this example we have defined a method which accepts the data as double array, creates and returns a Linecart. In the start method we are start() method we have invoked this method with three different data sets and displayed the resultant charts using a FlowPane.Exampleimport javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.chart.LineChart; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.scene.layout.FlowPane; public class MultipleLineCharts ... Read More

How to wrap the text in text flow layout in JavaFX?

Maruthi Krishna
Updated on 19-May-2020 13:29:53

611 Views

To create rich text contents in our applications JavaFX provides a special layout called text flow represented by the javafx.scene.layout.TextFlow class. Using this you can layout multiple text nodes in a single text flow.Since they are separate nodes, you can set different fonts to them. If you try to add nodes other than text to this layout, they will be treated as embedded objects and are simply inserted between the text.Wrapping the textUnlike Label and the Text nodes, TextFLow doesn’t provide any method to wrap the text. But it does have a property named prefWidth specifying the desired width of ... Read More

How to set alignment to text in text flow layout?

Maruthi Krishna
Updated on 19-May-2020 13:27:44

2K+ Views

To create rich text contents in our applications JavaFX provides a special layout called text flow represented by the javafx.scene.layout.TextFlow class. Using this you ca lay out multiple text nodes in a single text flow.Since they are separate nodes, you can set different fonts to them. If you try to add nodes other than text to this layout, they will be treated as embedded objects and are simply inserted between the text.Setting the text alignment −The textAlignment property of the TextFlow class specifies the horizontal alignment of the text in the layout. You can set the value to this property ... Read More

How to add the slider to a menu item in JavaFX?

Maruthi Krishna
Updated on 19-May-2020 13:25:44

248 Views

JavaFX sliderJavaFX provides a class known as Slider, this represents a slider component that displays a continuous range of values. This contains a track on which the number values are displayed. Along the track, there is a thumb pointing to the numbers. You can provide the maximum, minimum, and initial values of the slider.In JavaFX you can create a slider by instantiating the javafx.scene.control.Slider class.Menu ItemA menu is a list of options or commands presented to the user. In JavaFX a menu is represented by the javafx.scene.control.Menu class, you can create a menu by instantiating this class.A menu item is ... Read More

Advertisements