Demonstration of answer:(answered May 29 at 3:10 am)
**10/7/2016** you can find the code on
GitHub
Actual Question before answered:(asked May 22 at 19:53)
The title might be not too great but what I want to do is something like this in JavaFX:
Examples
YouTube:
StackOverFlow(which has and autocomplete):
Question: I don't require to write me the code for that. Instead I want to know how I can achieve that using JavaFX and some ideas.
Simple implementation of this code!
}
Also if u need different events for click on tag and click on "X" you can implement tagButton like this :
For the tags you can use a custom styled
HBox
containing aText
(the tag name) node an aButton
(the deletion button (X)). By playing around with the background and the border you can achieve the desired look of the tags.The
onAction
handler of the button should remove the tag from it's parent...For the whole tag bar you can use another
HBox
. Use the appropriate border for the correct look. In addition to the tags add aTextField
with no background as last element and set theHgrow
property of thatTextField
toPriotity.ALWAYS
to cover the rest of the available space.The
onAction
handler of thisTextField
adds new tags and clears the content of theTextField
.You could e.g. use ControlsFX's autocompletion features with the
TextField
or implement it on your own for a custom look...style.css
Here is a basic example of a tag bar (I wrote some code, because I think it's easier to follow). For the additional AutoComplete function you could use e.g. ControlsFx, as fabian already mentioned.
This is my version too
The whole Main class
its somehow long that's why.
But to sum up. You need a
1:
FlowPane
for the container, and you do not have to worry about wrapping,it will wrap itself, both vertical or horizontal.2:
Label
of course for your Text, which has aGraphicProperty
3:
Path
- well you could useButton
, and add aShape
orImage
to it, but that will be a lot of Nodes, so i usedPath
and i drew aX
red button.The rest is styling to your preferred color
EDIT something like this?
you can style it to get that output
use this line on the
TextField