How to let users interact with text in JavaFX? - javafx

I want to create a JavaFX tool where users annotate entities in text, such as persons. In JavaScript this is easy, for example:
<span onClick="openMenu('Joana')">Joana</span> eats an apple.
I can use the HTMLEditor class in JavaFX, but how can I call Java functions from within that HTML. Is that even possible? Or is there another way to create click listeners to words in text in JavaFX?

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

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.

Is it possible show a tree view in a tooltip in Qt?

Is it possible show a tree view in a tooltip in Qt? Or represent a tree view with a QString and then show it in a tooltip?
doc states:
The tip is a short piece of text reminding the user of the widget's function. It is drawn immediately below the given position in a distinctive black-on-yellow color combination. The tip can be any rich text formatted string.
Rich text displayed in a tool tip is implicitly word-wrapped unless specified differently with <p style='white-space:pre'>.
Then I would suggest the simplest way could be to use a nested HTML list, something like <ul><li>...<ul><li>...</ul>...</ul> that could be easy to get from your structure
I think you need create treeview dynamically and show it when user stop moving mouse.
Create widget containing QTreeView and name like ToolTipTree
Make TooltipTree to follow mouse
When user stop moving mouse, set ToolTipTree shown. I user move mouse again, hide ToolTipTree

Use Model/View on a QListWidget

Yes, you are right. We have QListView already, it is prefect when we are trying to display simple list with Model/View.
But, QListView has lots of problem when we need to display complex list with rich text and widgets. Just think about a timeline-listview for Facebook or Twitter.
Sure, we can implement our own delegate for rich text or images, but ListView can print static item only. So, there isn't a way to show clickable hyperlink (you can calculate position of the mouse and hyperlink, but it is a really drity work) or load asynchronous images.
Well, QListWidget seems our solution. We can put widgets into it. But. we will lost our Model/View/Delegate architecture, that is terrible!
Now, my solution is writing my listview in QML. Other widget are still native Qt widget. (I don't like a non-native pure QML user interface.)
QML is really flexiable when doing that kind of work. Then export my model, finally put a viewer into my QMainWindow. But coding in two programming languages and trying to communicate with other native widget is really difficult.
So, is there a way to use Qt's Model/View architecture with QListWidget? Or I have to implement them by myself?
QListWidget does use Qt's MVC, as it derives from QListView and...
QListWidget uses an internal model to manage each QListWidgetItem in
the list.
Just use QListWidget::model () const to access the model.

How to implement sortable list of object in Flex

I have list of object that I want each item to be rendered with some renderer that include a delete and edit buttons with some text.
What is the best way to make the list of object re-order-able in drag/drop fashion so the user can drag on item on top of another to change the order of the list.
Basically, just use a List, or DataGrid, with an itemRenderer that displays the buttons. Look into the DragEnabled, DragMoveEnabled, and DropEnabled properties for the click and drag sorting.
Look into using itemEditors for the edit functionality.
At the risk of sounding self indulgent, our DataSorter component is designed for sorting lists. It is modeled after the Netflix movie queue / YouTube Playlist editor, but can be easily modified or extended as needed. Free developer editions are available from the web site and you can check out our API Explorer sample.

Resources