Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8090750

Request - Make public and adept to overwriting the skins of the controls.

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: javafx
    • Environment:

      Windows 7 64x

      Description

      I wonder if it would be possible to turn the skin classes of JavaFX controls into public classes. For example, ScrollBarSkin, ButtonSkin, and so on. I would also like them to be adapted so that we developers could create subtypes of them, accessing and reusing their code. This would also be helpful for unlimited customization of existing controls in JavaFX technology.

      A clarification of this need can be well understood in the following text, initially placed here. This (large) text attest to the need for such a feature request came.

      Thank you for your attention, and forgive me about anything.




      BACKGROUND INFORMATION

      Morning JavaFX JIRA community. A few days ago I came across the need to perform certain task using JavaFX technology, and found a problem. Sought help in two Java communities on the subject, including Oracle, and unfortunately no one could give me any idea of what I could do (or at least no one said anything, not a word). I'm lost and I believe that my problem is something that can affect the lives of many programmers, because it involves the limitation of what we can do with JavaFX technology.

      The following will demonstrate my problem and also the approach used, coming to a dead end. I hope you notice that I did not want to teach anything to anyone here, but really demonstrate how I learned to do certain things. In summary, I will be demonstrating and proving what I'm talking about, and why I'm here. So here we go.

      RESUME

      There is a time I have been studying the new JavaFX technology, and I've been faced with some barriers in creating custom controls. I learned how to use CSS to customize my controls, and then I came across the case of customizing controls using Skin and SkinBase.

      Seen such resources, it was easy to initiate and complete the creation of new controls with visual and specific functionalities. However, personalization, that is, the visual and functional editing of existing controls on JavaFX library becomes somewhat more complicated. In many cases the programmer is forced to use resources that are only available in private packages from Oracle (com.sun ...), which would become a bad practice, resulting in the production of software not maintainable.

      Imagine the example where we want to customize the ScrollBar control. It is possible to change its appearance completely using CSS. However, the desire of adding new behaviors to such control involves creating a new theme from ZERO, without any reuse of ScrollBarSkin, because it is in the private Oracle package. This forces the programmer having to reimplement the logics that have already been implemented, such as the positioning from thumb, the update of values, what happens when you click the track, among many other things. In stubbornness to create a subtype of ScrollBarSkin it is seen that there are many important methods that have been encapsulated as not being overwritten, leaving you to have to compulsorily reimplement the existing logic.

      EXAMPLE

      To illustrate what I mean by this, and emphasize in the conclusion of this question in this community, we will briefly try to customize the ScrollBar existing JavaFX in package, using the means that I have learned. My intention is to create a scrollbar to look like this:

      http://s23.postimg.org/u2axiv1d7/scrollbars.jpg
      http://i.imgur.com/BjugoNL.jpg

      With regard to the behavior of the scrollbar, while clicking on its arrows, they should move a little, returning to their positions when the mouse button is released. When you pass the mouse over the thumb and arrows, they should light up. By clicking in the track or pushing any of our scrollbar arrows, the thumb must moves smoothly, in animated form and not abruptly.

      So let's start with our experiment. My approach here will initially create a CSS file that will serve as a definition of some appearances:

      http://pastie.org/8878459

      Observing my CSS file, we can see that I chose one of the 3 existing ways to connect our control to our skin, and I use the definition of property "-fx-skin" in my CSS file. Now I need to link our CSS file created with my control, right? This is done in Java code where I just have to set the CSS style sheet our control:

      scrollBar.getStylesheets().setAll(this.getClass().getResource("scroll-bar-style.css").toExternalForm());

      We already have my control linked to my Skin, but I have not really created the Skin. Creating or editing controls takes into account that the controls themselves, ie, the objects that extend Control, are considered part of the model of the MVC pattern, existing in JavaFX. The part of the control and visualization is originally divided (do not know for what reason) into two parts. One, called the Skin, and the other, called Behavior. Both are existing interfaces in JavaFX with Skin representing the Visualization part, and Behavior being the part of Control. Unfortunately (do not know why!) Behavior is considered a private part of the JavaFX package, so the users developers of JavaFX are pushed to treat the part of Visualization and Control inside the Skin (at least initially), which would be the part initially set for Visualization only. Having said all these strange things, let's create my Skin class:

      http://pastie.org/8878456

      As you can see, I insisted on creating a subtype of ScrollBarSkin, a private implementation of JavaFX (com.sun ...) package. I also want to make clear that I borrowed the BindableTransition class:

      http://pastie.org/8878462

      This is a class that I took from AquaFX library, so I have no credit for its creation. The original author, as written in the class itself, is hendrikebbers. I want to thank him/her and the AquaFX team for making available the source code of the library, without which I'd be lost.

      As you can see, ScrollBarSkin2 has the addEvents method, which is tasked to add certain events to certain components from skin. Largely, the animations are treated there. The heaviest problem of this code appears when I try to make the thumb to move smoothly once the user clicks on the track, or the arrow buttons. I just could not implement such behavior, because I have no idea how to do it. I've tried to override the handleControlPropertyChanged method, trying to create a proper positionThumb method. Unfortunately this was not possible because I need some ScrollBarSkin properties in order to properly position the thumb. Such properties would be, for example, trackPos and trackLenght, reserved to be calculated and used only in ScrollBarSkin.

      CONCLUSION

      I can then conclude that... I do not know what else to do. It is very annoying that Oracle provide JavaFX technology limiting its use (at least this is what appears). Appears to be no documentation on the study site that teaches this kind of customization. The documents on editing and creating custom controls in JavaFX existing on internet talk about the simple customization via CSS, not mentioning how we can implement more advanced features (such as animation of their substructures) within the skin. It makes me so frustrated, after all I see great potential in this technology (incomparable to Swing) and still not have the ability to use this feature. At the most, I felt myself powerless not knowing what to do. The existing books on the subject are completely outdated, and if not, they do not say anything more than the existing content here:

      http://docs.oracle.com/javafx/.

      QUESTION

      So what is seemingly possible are two things:

      1 – There is a need that part of the JavaFX API becomes public, making it easier for JavaFX users so they can develop better applications without limits imposed by technology. The part which should be public, should be at least all classes that implement Skin, existing in the JavaFX API, allowing developers to create their own controls, and also customize existing ones the way they want to. This would require that many methods and internal members of the Skin implementations became available, allowing the existence of subclasses. An example can be seen in the way AquaFX library was developed. So simple to use, and simple to maintain.

      2 – There is no need to leave part of the JavaFX API public. I'm being uninformed about the subject of personalization. Instead, there is then a need to improve the documentation to learn about JavaFX, so the users can understand in a practical way how to customize existing controls in JavaFX API, still allowing them unlimited customization. This would involve in the creation of a comprehensive and useful document demonstrating various teaching examples on how you can customize the controls in the current version of JavaFX. As a user programmer, my single most reliable source of study has always been here:

      http://docs.oracle.com/javafx/

      It would be great that such documents were featured on this site. I also learn through various other sources of study, but many are outdated, taking strange approaches which I have not the faintest idea if they are correct or not. And many do not even teach more advanced things.

      Well, I guess that's it. I appreciate JavaFX, and think it a work of art (its no wonder I'm here). I would love someone to comment on anything about the matter, and that these possibilities were actually discussed. I appreciate the attention and effort that you dedicate to JavaFX.
       
      Thank for your attention.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            loijfx Loa Krishna Oi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Imported: