tag:blogger.com,1999:blog-7706192646925495484.post5929899271004208294..comments2013-02-05T09:15:58.911-08:00Comments on Pleasing Software: Advanced JavaFX Control StylingAnonymoushttp://www.blogger.com/profile/10775967623378633903noreply@blogger.comBlogger23125tag:blogger.com,1999:blog-7706192646925495484.post-17942919885510768532012-06-27T23:08:41.887-07:002012-06-27T23:08:41.887-07:00HTML5 and CSS3 Design are best subjects among for...HTML5 and <a href="http://www.rizecorp.com/html5andcss3design.html" rel="nofollow">CSS3 Design</a> are best subjects among for web developers. These layouts are another stepping-stone to make the web encounter more pleasant and grafting.Anonymoushttps://www.blogger.com/profile/08832575795429023217noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-62065747327926857312010-08-06T06:57:56.525-07:002010-08-06T06:57:56.525-07:00Dean I have a question, about new SkinBase-way of ...Dean I have a question, about new SkinBase-way of implementation of new JavaFx controls.<br /><br />Right now I'm busy with implementation custom Dialogs for my application and it looks like this:<br /><br />var alert:JFxDialog = JFxDialog {<br /> titleText: "Warining about error!",<br /> icon:ImageView{image:Image{width:25, height:25, url:"{__DIR__}assets/Ico_Alert_32bit.png"}},<br /> content:Label {text:"hello window"},<br /> options:[DialogOption.OK_OPTION, DialogOption.CANCEL_OPTION]<br />}<br /><br />as you can see I use options for creating buttons in the bottom of the dialog.<br /><br />So, the question is how(where) I can create those buttons in my dialog skin? Cause when I try to read a sequence of my options and it has a size of 0.<br /><br />And one more question :)<br />In javafx 1.2 we had a skin reference in control and we could invoke smth in skin. Right now we use SkinBase and SkinAdapter in order to use CSS support, but in this case we don't have a reference to our Skinbase extended class. How I can get this reference?<br /><br />Thank you in advance.Anonymoushttps://www.blogger.com/profile/03043645254806539347noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-53679619635298601062010-07-27T08:17:32.031-07:002010-07-27T08:17:32.031-07:00The caspian style sheet is loaded by default. So ...The caspian style sheet is loaded by default. So you can just make your own style sheet and just start overriding the caspian styles. No need to copy the entire style sheet.<br /><br />Although the caspian style sheet is a good reference when creating your own styles.Anonymoushttps://www.blogger.com/profile/10775967623378633903noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-4813386709594195332010-07-27T03:32:31.805-07:002010-07-27T03:32:31.805-07:00Thanks Dean for this interesting post.
One questio...Thanks Dean for this interesting post.<br />One question about the use of caspian style.<br />Do you make a copy of the caspian css file and then customize it or do you load both caspian.css file and your own css ?Unknownhttps://www.blogger.com/profile/11679666938008031116noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-7145411666859976622010-05-12T00:34:23.681-07:002010-05-12T00:34:23.681-07:00Thanks for the comment, but I still need to find t...Thanks for the comment, but I still need to find the way to style HBox and VBox.Anonymoushttps://www.blogger.com/profile/03043645254806539347noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-49112048870409709122010-05-09T19:46:15.434-07:002010-05-09T19:46:15.434-07:00Dean and ishan,
Just to expand on Dean's comm...Dean and ishan,<br /><br />Just to expand on Dean's comment about states: they can be easily achieved based on a status variable. Suppose you have the states red, green and blue. Then the corresponding CSS may be:<br /><br />.button#red {-fx-base: red;}<br />.button#green {-fx-base: green;}<br />.button#blue {-fx-base: blue;}<br /><br />As JavaFX doesn't give us more functional defs, (yet?), I like to define constants as Java enums, e.g., for the above states I'd define Status.java:<br /><br />public enum Status {red, green, blue}<br /><br />Then a button styled based on the status is simple:<br /><br />Button {text: "Chameleon"<br /> var status = Status.red; <br /> id: bind "{status}";<br />}<br /><br />For instance, if we introduce a next() method to go from one state to another in the Status.java:<br /><br />public enum Status {<br /> red {<br /> public Status next () {return green;}<br /> },<br /> green {<br /> public Status next () {return blue;}<br /> },<br /> blue {<br /> public Status next () {return red;}<br /> };<br /> abstract public Status next ();<br />}<br /><br />Then the button that changes style when clicked becomes simply:<br /><br />Button {text: "Chameleon"<br /> var status = Status.red;<br /> id: bind "{status}";<br /> action: function () {status = status.next()}<br />}<br /><br />Of course we could also bind the id to an outside status variable...<br /><br />Actually, I'd find it much more appropriate to use styleClass rather than id attribute, i.e.:<br /> styleClass: bind "{status}";<br />After all, a widget should not be identified by its style; it's even a good idea to have unique ids, e.g. for look-ups. But I didn't get styleClass to work with -fx-base, only with -fx-text-fill, and only partially. (Do you have any idea why - a bug?)havajskyhttps://www.blogger.com/profile/09562781101290826003noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-42537910622831509482010-05-01T08:46:39.859-07:002010-05-01T08:46:39.859-07:00Hi Dean.
Is there any way to style HBox and VBox? ...Hi Dean.<br />Is there any way to style HBox and VBox? I'd like to make a round border and background color for my application.<br />Thanks.Anonymoushttps://www.blogger.com/profile/03043645254806539347noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-30234566134048619712010-04-30T13:31:11.467-07:002010-04-30T13:31:11.467-07:00Hi, dean.
I know and see the aim of css. Normally,...Hi, dean.<br />I know and see the aim of css. Normally, in web culture, there was and is a trend to create ui in css. In 1.2, I created my software api in a way that user can change the theme by both css (I love css approach for its simplicity) and skin. It was working well except the bug for dynamically created nodes. For 1.3, I have to redesign the skinning architecture of my software. Again I want to benefit from both static (css) and dynamic (skin) way of styling. For a consistent api, I need to learn every aspects of styling and estimate possible changes that can be made by fx-team. In this sense, your postings are very fulfilling, and I'm forwarding my thanks. If you looked at Sergey's codes, in fact the css button is very simple and short. If there were a way of overriding css styling in some parts, it would be very useful. Maybe there is. But I couldnt find a way yet.ihsanhttps://www.blogger.com/profile/14066255364640966228noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-4038217616746182942010-04-30T08:01:15.350-07:002010-04-30T08:01:15.350-07:00ihsan,
Yes and I think Sergey's misunderstand...ihsan,<br /><br />Yes and I think Sergey's misunderstanding when you would use CSS. CSS is not meant to be a replacement for writing the logic of your control. You still need to do that in JavaFX.<br /><br />CSS is only meant to allow people to easily change the look of *existing* controls. If a control doesn't *behave* the way you want, no amount of CSS will change that. See my response to him in the other post.<br /><br />If you do want to programmatically change the color of a button with CSS you would simply create two different styles:<br /><br />.button {<br /> -fx-base: blue;<br />}<br /><br />#red-button {<br /> -fx-base: red;<br />}<br /><br />These styles turn all buttons blue. But any button (any control, actually) with the ID of "red-button" will be red. From here you just change the ID of the button:<br /><br />btn = Button {<br /> text: "I'm a Button"<br /> action: function() {<br /> if (btn.id == "") btn.id = "red-button" else btn.id = ""<br /> }<br />}<br /><br />Now every time you click the button it changes between blue and red. <br /><br />Tip: If you find yourself trying to write logic using CSS hacks, you're probably not using CSS as God, or Jasper, intended. :-)<br /><br />DeanAnonymoushttps://www.blogger.com/profile/10775967623378633903noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-20620327124910949302010-04-29T13:27:27.905-07:002010-04-29T13:27:27.905-07:00Dean, have you ever looked Sergey's codes abou...Dean, have you ever looked Sergey's codes about styling? He's right about lack of bind support in css. Also in his example, it cannot be given colors programmatically to css styled controls.<br />I tried the following workaround. But<br /><br /><br />override var style = bind "-fx-base:{toColorString(coColor)};";<br /><br />function toColorString(coColor:Color) {<br /> "rgba({coColor.red*255 as Integer},{coColor.green*255 as Integer},{coColor.blue*255 as Integer}, {coColor.opacity})"<br />} <br /><br /><br />But style from css overrides style from node. it should be vice versa, shouldnt it?ihsanhttps://www.blogger.com/profile/14066255364640966228noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-54878335238286714912010-04-29T09:35:57.130-07:002010-04-29T09:35:57.130-07:00@Jan: I just realized that I missed your question....@Jan: I just realized that I missed your question. Sorry about that. You are correct, you cannot style arbitrary public variables any more (at least I can confirm that I can't get it to work, either).<br /><br />I suspect that this functionality was sacrificed for performance in the new CSS engine. But I'm hoping they will soon find a way to restore it. <br /><br />DeanAnonymoushttps://www.blogger.com/profile/10775967623378633903noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-1011507956505522322010-04-29T09:27:42.191-07:002010-04-29T09:27:42.191-07:00@D It looks like States are gone, at least for now...@D It looks like States are gone, at least for now. Which is really, really disappointing. And I appreciate the thought, but I'd rather write code than tutorials. And I'd rather write about what interests me; not an option you usually get once it turns into a job. :-)<br /><br />@David: Sub-regions are next on my list. Hopefully I'll get time this weekend to dig into that and write up what I find (unless someone beats me to it *cough* Oracle *cough*). :-)<br /><br />DeanAnonymoushttps://www.blogger.com/profile/10775967623378633903noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-29449235694978227242010-04-28T14:20:13.933-07:002010-04-28T14:20:13.933-07:00Hmm - played with examples and lots of thoughts to...Hmm - played with examples and lots of thoughts to play with, but ... this is great for the simple example but how do we actually create a skin with multiple regions?<br /><br />e.g. a very simple case of a slider on a bar (as already provided by javafx but just for illustration here) then I assume the bar would be one region and the slider another identified by id? How are the two parts defined? <br /><br />Trying to work it out, as would like to apply to xpicker, but any hints would be very useful ( and yes, I acknowledge caveats with implementation) :-)Unknownhttps://www.blogger.com/profile/03619465822686337623noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-51758435972737699332010-04-28T11:40:04.753-07:002010-04-28T11:40:04.753-07:00COOOOL
but the one thin I miss from Caspian is St...COOOOL<br /><br />but the one thin I miss from Caspian is States. For example when you are making a component to set different styles for different states of the component.<br /><br />P.S.<br />Dean, I think Oracle should hire you to right a JavaFx tutorials.Anonymoushttps://www.blogger.com/profile/03043645254806539347noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-7930690349744241432010-04-28T04:38:46.641-07:002010-04-28T04:38:46.641-07:00@Dean,
I haven't explore much of CSS in my ap...@Dean,<br /><br />I haven't explore much of CSS in my application. Had the plan to use in JavaFX 1.3. <br />Got little confused.<br /><br />Thanks Dean<br /><br />@jsmith<br /><br />I must have explored a little and tried some CSS code before posting this :) Thanks Jsmith.Khttps://www.blogger.com/profile/01479772066144410324noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-56134913921592438662010-04-27T13:56:59.683-07:002010-04-27T13:56:59.683-07:00Dean, thx a lot for this post. The writing style ...Dean, thx a lot for this post. The writing style and depth of information is excellent.<br /><br />I was playing around with the JavaFX CSS on the weekend and found it fun but cryptic. With the info in your post, now it is just fun :-)<br /><br />The multi-background stuff and the differences between spaces and commas was confusing me, but now it makes sense.<br /><br />Those without a web design background who need a css refresher, check out => http://www.w3schools.com/css/default.asp<br /><br />I wish that some of the standard css names (non -fx prefixed) like margin or padding worked out of the box in JavaFX. It would also be great if some of the non-standard extensions such as (https://developer.mozilla.org/en/CSS_Reference/Mozilla_Extensions) worked too. That way, it would be easier to port existing stylesheets to Java and existing stylesheet editors, like netbeans, could do better syntax checking and highlighting.<br /><br />It would also be nice to able to completely layout a scene using css in addition to easily styling a control. Perhaps this is already possible with the existing 1.3 implementation...<br /><br />The JavaFX css system is confusing, a bit complicated, non-w3c standard and undocumented, but I do prefer the css system for doing a lot of things over coding a lot of styling and layout stuff in JavaFX script, especially if it allows you to cut the compile/run steps out of the change, compile, run, test cycle.<br /><br />Kishore: I think you can do exactly what you want with JavaFX css - your demo code will just work.<br /><br />Ah, long comment, perhaps I should just start my own blog . . . there is a lot more to cover on this topic ;-)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-3800438790002670892010-04-27T13:23:45.083-07:002010-04-27T13:23:45.083-07:00Great post, many thanks!
But: you are showing on...Great post, many thanks! <br /><br />But: you are showing only how to set the predefined -fx properties. In 1.2 I could set in CSS values of the public properties/variables in my custom skin. This doesn't work anymore, at least not in the same way. Hopefully it's only the syntax that changed:) If so, can you advise?havajskyhttps://www.blogger.com/profile/09562781101290826003noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-62316245664735329562010-04-27T09:54:35.140-07:002010-04-27T09:54:35.140-07:00Nice stuff, We need more tutorial like this.Nice stuff, We need more tutorial like this.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-69109588624770684322010-04-27T08:04:06.965-07:002010-04-27T08:04:06.965-07:00Sergey: This article is intended as an exploration...Sergey: This article is intended as an exploration of the new CSS skinning support in v1.3 (the code in your article is still pre-1.0 by the way). More complex controls are certainly possible, but we have to start somewhere when figuring out what this new system is capable of.<br /><br />Kishore: This article is admittedly more from the perspective of a control author than an app developer. But what you want to do is certainly possible. You can create your own style sheet with a .button selector and change the -fx-base (background color), the -fx-font, the -fx-opacity, etc. Then all buttons in your scene will pick up the new style.<br /><br />Goddard: They are private for now. Authors of custom controls do need to start understanding them because this is the way styling will work from now on. When the JavaFX team is satisfied with the API it will go public. You can learn it then, if you prefer. :-)<br /><br />And I would argue that learning the underlying bits also gives app developers a better understanding of what they can and cannot do in their stylesheets.<br /><br />David: There are apparently still some issues with the more complex selector statements. For now, you'll have to find a different way to select the menu items in the choice box's popup menu.Anonymoushttps://www.blogger.com/profile/10775967623378633903noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-38275865433355396002010-04-27T04:35:47.136-07:002010-04-27T04:35:47.136-07:00Great helper as ever - thanks for your digging :-)...Great helper as ever - thanks for your digging :-)<br /><br />Now - anyone actually tell me what this is from the stylesheet as seems to affect a number of the bits of interest to me and I dont have access:<br />/* TODO RT-7542 replace this with ".choice-box *.popup-menu *.menu-item" once bug is fixed */Unknownhttps://www.blogger.com/profile/03619465822686337623noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-29041531996886393612010-04-27T04:28:10.347-07:002010-04-27T04:28:10.347-07:00Interesting, indeed. Too bad it's based on pri...Interesting, indeed. Too bad it's based on private APIs.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-54659488844471174772010-04-27T02:37:55.431-07:002010-04-27T02:37:55.431-07:00I felt it is little confusing. The relation betwee...I felt it is little confusing. The relation between components,<br />skin -> SkinAdapter -> DemoControlRegionSkin -> etc etc<br /><br />It reminds me the days when I was developing SWING LookAndFeel, all those complex API for minor change's.<br /><br />With JavaFX 1.3 I expected a easy and (understandable way) of specifying CSS styles to components something like in Adobe Flex. <br /><br />something like <br /><br />Button {style:"myCSS"}<br /><br />OR<br /><br />MyButton extends Button {<br /> style:"myCSS"<br />}<br /><br />and use it <br /><br />scene: Scene {<br /> content: [ MyButton {} ] }<br /><br />May be I need to read it again to understand.Khttps://www.blogger.com/profile/01479772066144410324noreply@blogger.comtag:blogger.com,1999:blog-7706192646925495484.post-32624185973951654772010-04-27T02:03:57.646-07:002010-04-27T02:03:57.646-07:00Why those components so simple? Look old article a...Why those components so simple? Look old article about user defined datepicker component:<br /><br />http://java.dzone.com/tips/javafx-component-creationSergey Surikovhttps://www.blogger.com/profile/04557461291711158028noreply@blogger.com