What kind of button does DatePicker and ComboBox use? - javafx

I have been trying to find the button that DatePicker and ComboBox uses. I have searched through ComboBoxBase, and all other similar classes, and have been unable to find it. Is there a public version of this?

There is no ComboBoxButton class or public method that creates such a thing. You can try to reproduce what's done in the specific controls by referring to the source code.
The look of the JavaFX controls are defined in their skin classes; so ComboBoxBaseSkin for ComboBox, with some supporting classes for the popup and list view that's displayed inside the popup. For the most part, the skin class defines the layout and behavior (i.e. response to user input), and the actual look (shape of the arrow, colors, etc) is defined by the CSS file.
These buttons are defined in a pretty non-trivial way; for ComboBox the arrow itself is defined as a Region, which is placed inside the arrowButton, which is a StackPane. Then the CSS file defines the shape of the arrow and different colors and borders depending on whether it's pressed, selected, etc.
The source for JavaFX is available via OpenJFX:
Home
ComboBoxBaseSkin
modena.css
In the CSS file, I would search for combo-box (there's a couple of dozen occurrences), and pay particular attention to the .arrow-button and .arrow classes.

Related

How do I write JavaFX custom property editors for custom controls

We have developed a number of custom JavaFX controls which we build into a JAR and then allow our clients (internal and external) to load into SceneBuilder and then create UI's with those controls. We would like to attach custom property editors to some properties on these controls.
As a made up example, say we have a GraphControl that displays line graphs. It has multiple properties, one of which is "TickStyle", an enum with options DOT, CROSS, CIRCLE, BIG_TICK_STYLE, SMALL_TICK_STYLE, etc.
Now, when I insert this control into SceneBuilder (as a JAR), I can drop instances onto the design canvas. Cool. But I don't want a boring combo-box of tick style values (the enum's toString) e.g. "BIG_TICK_STYLE", but a pretty picker with graphical representations.
The JavaBean spec has the PropertyEditor interface and the BeanInfo thing which does the same thing for Swing. Does this work for JavaFx and how? If it doesn't work for JavaFX, then is there an alternative?
We really don't want to go down the route of hacking SceneBuilder, we just don't have time or people for that.
Thanks!
UPDATE 1
SceneBuilder seems to have its own complex property editors, e.g. for colours. We need editors for
more complex property types (to any level of complexity) such as the Insets editor
more complex editors, such as the colour editor

Xamarin Forms Button set Content

I have a very common problem, but I couldn't find any valid solution.
I want to create a Button able to contain more than a simple Label or Image. In fact, Xamarin Button exposes only Text and Image properties, but in my case I want to construct a more flexible set of controls (e.g. a StackPanel with a list of controls).
I implemented a ContentView acting as a Button after having added TapGestureRecognizer and it works from the pure functional point of view. What I don't like is the missing of all Visual States of a Button.
Therefore, I was thinking how to implement a Custom Renderer of a Button. I would like to expose a ContentPresenter BindableProperty and then set that property to the Button.Content (speaking in UWP terms) in the Renderer class. I think this could be a solution, the problem is that I don't know how to "cast" a Xamarin.ContentPresenter to a UWP.ContentPresenter. Do you have any idea about how to implement a Button able to contain any generic Content?

What are the advantages of putting TextField inside Button (JavaFX)

In SceneBuilder it is possible to put TextField inside a Button:
Is it for just decorative purposes or it has some functionality like when clicking button it gets child info and so on? If it has some functionality, are there any examples?
From the documentation:
A simple button control. The button control can contain text and/or a
graphic.
The graphic is changeable for every subclass of Labeled.
You can put any node as graphic into e. g. the button. It gives you a very high level of customization.
A good example is the customization of the header of a TitledPane.
As for your concrete example I see no advantage, rather a disadvantage as it's not common to have a textfield inside a button. But you nevery know with what people come up with.

JavaFX and CSS Basic ?'s (regarding Checkboxes)

I have a couple questions regarding JavaFX (1.3) and CSS. First of all, when I create a CheckBox node and set its styleclass, I can't actually get the checkbox to show up. It just looks like a text-label. Do I have to specify something specific to actually get the checkbox to appear?
Also, what is the CSS class/id I would use to modify all checkboxes in a program?
Have you read the JavaFX CSS Reference Guide?
http://download.oracle.com/docs/cd/E17802_01/javafx/javafx/1.3/docs/api/javafx.scene/doc-files/cssref.html
I think the place you need to look at is this forum post:
Styling a checkbox and also:
Checkbox in the UI controls
I had similar issues with ListBox where the control is constructed from a number of components and has a bunch of different pseudo classes to be 'configured' depending on what you need it do look-like.
The Styling a checkbox thread points you to the javaFX runtime: $lib\ext\jfxrt.jar.
If you look in: com/sun/javafx/scene/control/skin/
caspian/caspian.css
moderna/moderna.css
You get the full naked 'defaults' CSS for the your controls. That said I am on here today to find out
A method to algn JavaFX checkbox label text with the text on a line
... how to align the text base-line, so there's still work to do before it just magically looks right lol

Flex: Modify an embedded icon and use it in a button?

Just that, if you embed an icon:
[Embed(source='icons/checkmark.png')]
private static var CheckMark:Class;
You end up with a dynamic class. You can pretty easily assign the icon to a button at runtime by calling the setStyle method:
var btn:Button = new Button();
btn.setStyle("icon", CheckMark);
But what if you wanted to alter the icon at runtime, like changing it's alpha value or even redrawing pixels, before assigning it to the button?
So far I can't find a satisfactory answer...
This is the only answer I could find that seemed close: Dynamic Icons (example with View Source)
His solution involves a custom "DynamicIcon" class which is used in the button's icon setting, and a custom Button class which adds one method to the Button class to draw dynamic icons.
The end result is that you are able to send BitmapData to the DynamicIcon class, which will show up in the button. So, embed your image, instantiate your asset class, get the bitmapasset and modify it however you need to and send the bitmapData to the icon.
It's an interesting problem and it seems like there should be an easier solution, but this works without a lot of hassle.
The way I'd solve this is to implement a programmatic skin class that draws the icon itself manually. There's probably more work you'll have to do to ensure the button calculates the correct size as if it has an icon even though it doesn't. You may have to poke through the Button source code to look at how the reference to the icon is stored.
I love just creating programmatic skins that do exactly what I want and then using interesting CSS declarations to modify states - for instance:
button.setStyle("customIconAlpha", .4);
and then of course the skin or the custom button class would have:
var alpha:Number = getStyle("customIconAlpha") as Number;
(not sure if you have to typecast that one)
The big problem I found with programmatic skins is that the button refuses to measure the width/height. I easily got around this by overriding the get methods for each:
override public function get width():Number { return WIDTH; }
override public function get height():Number { return HEIGHT; }
In my case I needed to modify buttons in a TabNavigator, hence no easy way to subclass the button. Thankfully, the parent of each skin is the button, so using static methods within your skin, you can identify the instance of the Button to which the icon skins belong.
If you're using the cover-all "icon" style, a new skin object will be created for each state. So you'll need to keep this in mind when changing the state of the icons.

Resources