3

Does Java provide any extended default pack of icons usable for each Swing and JavaFX frameworks? I mean arrows, warnings, files, errors, notifications, shapes, hands..

I am aware of downloadable unofficial ones and easily to be imported. I ask if there some included within Swing or JavaFX do exist and if so, how to access them.

For example I'd like to use them as the icon of the item available in a ComboBox etc.


I have found this webpage dealing with a similar issue in Swing, however it doesn't fully answer my question, moreover I am looking for a JavaFX stuff as well.


OT: For ones who vote ths question to be closed as OT, I don't ask for any recommend tool, software library, tutorial or other off-site resource. I ask for the official one.

Nikolas Charalambidis
  • 40,893
  • 16
  • 117
  • 183
  • 1
    Obviously those images reside in the standard jars. However some things in jafafx are simply drawn by the program. e.g. part of the CSS style for the arrow of a `ScrollBar` arrow: `-fx-shape: "M7.071,1L8.5,1.002L4.5,4l-4-2.998L1.93,1L4.5,2.976L7.071,1z";` (=SVG path) – fabian Jun 19 '16 at 16:23
  • 1
    In [tag:javafx], more on `SVGPath` may be found [here](http://stackoverflow.com/a/32116938/230513). – trashgod Jun 19 '16 at 17:07
  • 1
    For pure icons and not svgpaths, you are probably best off going with a 3rd party font access library such as [FontAwesomeFX](https://bitbucket.org/Jerady/fontawesomefx) or [GlyphFonts from ControlsFX](http://controlsfx.bitbucket.org/org/controlsfx/glyphfont/GlyphFont.html), as those will provide you access to a much wider array of fonts than the (currently extremely limited) set that is distributed with JRE 8. – jewelsea Jun 22 '16 at 18:11

1 Answers1

6

JavaFX answer

There are a lot of icons baked into JavaFX, but using them is not documented and not really the way to go, since it may change in the future.

But if you want to go down that route, you will first need to extract the JavaFX stylesheet modena.css which is described over here.

Now you will find all sorts of examples on how to use JavaFX CSS and two types of these built in icons:

  1. Icons as SVG shapes, usually defined with the CSS attribute -fx-shape
  2. Icons as images, usually defined with the CSS attribute -fx-graphic

If you picked a symbol and now want to use it, you have to reproduce the exact hierarchy with the exact same style classes to apply the same style.

Example for SVG: Let's say you are interested in the cross of .default-color3.chart-symbol

@Override
public void start(Stage pPrimaryStage) throws Exception
{
    final StackPane graphic = new StackPane();
    graphic.setMaxSize(25, 25);
    graphic.getStyleClass().addAll("default-color3", "chart-symbol");

    pPrimaryStage.setScene(new Scene(new BorderPane(graphic), 500, 500));
    pPrimaryStage.show();
}

Example for a graphic: The HTML Editors cut icon:

@Override
public void start(Stage pPrimaryStage) throws Exception
{
    final Label graphic = new Label();
    graphic.getStyleClass().add("html-editor-cut");
    pPrimaryStage.setScene(new Scene(new BorderPane(graphic), 500, 500));
    pPrimaryStage.show();
}
eckig
  • 10,964
  • 4
  • 38
  • 52
  • Thank you for the answer. I am about to award your answer with bounty and discover both of ways even the second one seems to be easier to understand. Is anythere an observable chart of these symbols such as `html-editor-cut` is? I don't know all their names and I'd like to see them before using. – Nikolas Charalambidis Jun 22 '16 at 12:45
  • @NikolasCharalambidis as I explained in my answer: Extract `modena.css` from your JavaFX jar and search it for the keywords. Other than that there is no official documentation. – eckig Jun 22 '16 at 13:55