Institute of Computer Science
  1. Courses
  2. 2017/18 spring
  3. Object-Oriented Programming (Narva College) (P2NC.01.083)
ET
Log in

Object-Oriented Programming (Narva College) 2017/18 spring

  • Home
  • Materials
  • Java Glossary
  • Source Example
  • Cheat sheet (S1-S6)
  • Grading
  • Links
Session 7

Effects

It is possible to use visual effects to enhance the look of our JavaFX application. All effects are in javafx.scene.effect package and are the subclasses of Effect class. For more information about particular classes, methods, or additional features check the API documentation.

Useful link:

Examples of some effects can be found here.

The following example demonstrates setEffect method which let us highlight different effects. In this example, a green shadow is set to the button.

    public void start(Stage primaryStage) {
        // Create a scene and place a button on the scene
        StackPane pane = new StackPane();
        Button ok = new Button("OK");

        // create a shadow effect to the button
        DropShadow shadow = new DropShadow(20, Color.GREEN);
        shadow.setOffsetX(20);
        ok.setEffect(shadow);

        pane.getChildren().add(ok);
        Scene scene = new Scene(pane, 200, 50);
        primaryStage.setTitle("Button in a pane"); // set the stage title
        primaryStage.setScene(scene); // place the scene on the stage
        primaryStage.show(); // display the stage
    }

Try out

Compile and run the code above.

Try other effects by yourself.

Session 7
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment