mihosoft.eu
Programming, Art, Linux, Free Software…
mihosoft.eu
Navigation
  • Home
  • VRL-Studio
  • SonoAir
  • Monochrome Wars
  • About
  • Impressum
  • Datenschutz
You are here: Home › Java › Adding Custom Icons to JFXtras Window Control (VFXWindows)

Adding Custom Icons to JFXtras Window Control (VFXWindows)

August 22, 2013 | Filed under: Java, JavaFX, Uncategorized, VRL and tagged with: Java, JavaFX, JFXtras, JInternalFrame, MDI, VWorkflows, window control, Window Node, Window System, workflow, workflows

Adding custom Icons:

The window control comes with some predefined icons. But it is also possible to provide custom icons.

To add a custom icon just add it via either getRightIcons().add(myIcon) or getLeftIcons().add(myIcon). The action of an icon can be defined by defining an EventHandler via setOnAction(..).

Example:

    WindowIcon customIcon = new WindowIcon();
    customIcon.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent t) {
            // we add a nice scale transition
            // (it doesn't do anything useful but it is cool!)
            ScaleTransition st = new ScaleTransition(Duration.seconds(2), w);
            st.setFromX(w.getScaleX());
            st.setFromY(w.getScaleY());
            st.setToX(0.1);
            st.setToY(0.1);
            st.setAutoReverse(true);
            st.setCycleCount(2);
            st.play();
        }
    });

    // now we add our custom icon
    w.getRightIcons().add(customIcon);

The result will look like this:

Window Control: Custom Icon

Window Control: Custom Icon

Tip:

It is recommended to use CSS to style the icon. The best way to do this is by specifying an SVG path in the style. To do so use -fx-shape and paste the path there. Here is an example how it is done for the CloseIcon:

First, define the style class:

 customIcon.getStyleClass().setAll("window-close-icon");

And here’s the corresponding entry in the CSS file:

.window-close-icon {
  -fx-skin: "jfxtras.labs.internal.scene.control.skin.window.DefaultWindowIconSkin";
  -fx-border-color: rgb(255,255,255);
  -fx-shape: "m 81.451435,47.885404 -39.71427,39.714277 m 0,-39.714277 39.71427,39.714277 m 27.285725,-19.85714 c 0,26.03628 -21.106585,47.142859 -47.142865,47.142859 -26.03628,0 -47.14285,-21.106579 -47.14285,-47.142859 0,-26.036277 21.10657,-47.142853 47.14285,-47.142853 26.03628,0 47.142865,21.106576 47.142865,47.142853 z";
  -fx-border-width: 2;
  -fx-border-insets: 1;
}

Conclusion

As you have seen it is not complicated to add custom icons to the window control. The behavior of the icons is fully customizable.

Fedback

If you have further questions or if you found a bug feel free to contact me! You are also welcome to contribute to the project via GitHub.

Stay tuned and follow me on Twitter

Did you like this article? Share it with your friends!

Tweet

Written by admin

Visit my Website Follow me on Twitter

8 Responses to "Adding Custom Icons to JFXtras Window Control (VFXWindows)"

  1. Tomas Lund Petersen says:
    August 23, 2013 at 15:55

    Hi, Nice example, A couple of questions. Why is Window taking a default style different from javafx default? Can you point me to jfxtras 2 window documentation? i couldn’t find it in jfxtras.org Tks,

    Reply
    1. miho says:
      August 23, 2013 at 22:47

      Hi, Nice example

      Thanks.

      Why is Window taking a default style different from javafx default?

      For the internal frames I always use custom styles. Like for my VWorkflows based applications.

      Can you point me to jfxtras 2 window documentation? i couldn’t find it in jfxtras.org Tks,

      The documentation consists of the javadoc and the posts in the JavaFX category on this blog. Just ask if you have questions.

      Michael

      Reply
  2. Tomas Lund Petersen says:
    August 23, 2013 at 23:27

    Michael, Tks for the insights. I ended up editing the .css but i’m still not satisfied with it. Which would be the recommended way to do something like: stage.getIcons().add(new Image(URSULAICON)); in JFXtras Window Control. At first tried using the w.getLeftIcons().add(new Image(URSULAICON)); but off course that wouldn’t work and then tried to extend WindowIcon but i figured that wasn’t the right way because i don’t want to manage any action. I would appreciate your comments, Tomas

    Reply
    1. miho says:
      August 24, 2013 at 00:40

      How about css background?

      Example:

      .window-close-icon {
        -fx-background-image: url("your_image.png");
        -fx-background-size: 100% 100%;
        -fx-border-color: transparent;
        -fx-shape:null;
      }
      
      Reply
  3. Tomas Lund Petersen says:
    August 24, 2013 at 18:24

    hi, finally made it work. I created a WindowIcon icon, seted the style class, added the class to the css, and added the icon to the leftIcons List. Window creation: Finding the way to set the Style class was tricky, its not intuitive at all. WindowIcon ursulaIcon = new WindowIcon(); ursulaIcon.getStyleClass().setAll("window-ursula-icon"); w.getLeftIcons().addAll(ursulaIcon );

    css definition. ursulaIcon.png is in the same path as the .css it wouldn’t work otherwise despite using the path like “kamikazee/ursula/client/res/img/ursulaIcon.png” wich works in new Image(“kamikazee/ursula/client/res/img/ursulaIcon.png”); .window-ursula-icon { -fx-skin: "jfxtras.labs.internal.scene.control.skin.window.DefaultWindowIconSkin"; -fx-background-image: url("ursulaIcon.png"); -fx-background-size: 100% 100%; -fx-border-color: transparent; -fx-border-width: 1; -fx-border-insets: 1; -fx-shape:null; }

    OK that is it.I’m not a css programer and i don’t like to be forced to set properties by css but it works, Thank you, Tomas Lund Petersen

    Reply
  4. JavaFX links of the week, August 26 // JavaFX News, Demos and Insight // FX Experience says:
    August 25, 2013 at 23:41

    […] has a post about adding custom icons to the JFXtras Window control (also known as […]

    Reply
  5. Volel Mondesir says:
    April 10, 2022 at 15:20

    i would like to remove the title bar in may internal window

    Reply
  6. Volel Mondesir says:
    April 10, 2022 at 15:21

    i would like to remove the title bar in may internal window i need your help

    best regards

    Reply

Leave a Reply to Tomas Lund Petersen Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pages

  • About
  • Datenschutz
  • Impressum
  • Seminar 2019

Categories

  • 3D Printing
  • Any-Key
  • Art
  • C/C++
  • Devoxx
  • Digital Painting
  • Featured
  • IoT
  • Java
  • JavaFX
  • Javakurs 2015
  • JavaOne
  • Linux
  • Linux on Apple Hardware
  • Linux: Daily Usage Tips
  • Mobile Apps
  • Mobile Devices
  • Programming Languages
  • Repair Things
  • Science
  • Sonos
  • Teaching
  • Uncategorized
  • Virtual Reality
  • VRL

Tags

3D 3D Printing 3d visualization AirSonos Apple Music Devoxx Devoxx 2013 gradle graph iOS Java Java 8 JavaFX JavaFX 8 JavaOne JavaOne 2013 jdk9 JFXtras JInternalFrame Linux MacBook MDI mobile apps OpenDive OpenJDK OpenJFX Open Source Performance scientific visualization SonoAir Sonos Ultimaker Virtual Reality Virtual World visual programming VPlot VRL VRL-Studio VWorkflows window control Window Node Window System workflow workflows X11

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

JavaOne Rockstar

JavaOne Rockstar
Follow @mihosoft

Recent Posts

  • Native JDK9 Application Bundles
  • Running C code from Java via VTCC
  • SonoAir finally supports macOS High Sierra!
  • JavaOne 2017 Community Keynote Artwork
  • The JGrounds App: better teaching apps for Java 9 [BOF5047]

Recent Comments

  • ¿Ventanas completamente personalizadas de JavaFX? - Fallosweb.com on VFXWindows
  • JavaFX entirely customized windows? – w3toppers.com on VFXWindows
  • Volel Mondesir on Adding Custom Icons to JFXtras Window Control (VFXWindows)
  • Volel Mondesir on Adding Custom Icons to JFXtras Window Control (VFXWindows)
  • Switching between different JDK versions in Windows - ErrorsFixing on JSelect: switch between different JDK versions

Archives

  • February 2018
  • October 2017
  • September 2017
  • February 2017
  • June 2016
  • May 2016
  • November 2015
  • September 2015
  • July 2015
  • March 2015
  • September 2014
  • March 2014
  • February 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • November 2010
  • February 2010
  • November 2009
  • October 2009
  • February 2009
  • August 2008
  • May 2008
  • April 2008
  • March 2008
Privacy & Cookies: this site uses cookies. By continuing to use this website, you agree to their use.
To find out more, see here: Impressum & Datenschutz

© 2025 mihosoft.eu