Tuesday, 20 October 2020

JavaFX: Shape: smooth: Apply rendering hints

‘smooth’ is a Boolean property, if it is set to true, rendering hints are applied to the shape. If ‘smooth’ property is set to true, then anti-aliasing techniques are applied to smoothen the shape.

 

<Rectangle fx:id="rectangle" arcHeight="30" arcWidth="30" fill="gray" width="300" height="100" smooth="true"/>

 

Find the below working application.

 

HelloFxmlDemo.fxml

<?import javafx.scene.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<StackPane xmlns:fx="http://javafx.com/fxml" fx:controller="com.sample.app.controller.HelloWorldController">

	<Rectangle fx:id="rectangle" arcHeight="30" arcWidth="30" fill="gray" width="300" height="100" smooth="true"/>
	
	<Text fx:id = "text" fill="lightsalmon" text="Hello World" style="-fx-font-weight: bold; -fx-font-size: 30" />

</StackPane>

 

HelloWorldController.java

package com.sample.app.controller;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;

public class HelloWorldController implements Initializable{
	
	@FXML
	private Rectangle rectangle;
	
	@FXML
	private Text text;

	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// Write custom logic here
		
	}

}

HelloFXML.java

package com.sample.app;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class HelloFXML extends Application {

	public static void main(String args[]) {
		launch(args);

	}

	@Override
	public void start(Stage primaryStage) throws Exception {

		Parent root = (Parent) FXMLLoader.load(HelloFXML.class.getResource("/HelloFxmlDemo.fxml"));

		Scene scene = new Scene(root, 500, 500, Color.WHITE);

		primaryStage.setTitle("StackPane Demo");
		primaryStage.setScene(scene);
		primaryStage.show();
	}

}


Output



 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment