In the Borland VCL library, almost all controls had a hint property. During runtime, when you position mouse over the respective control, a small box with the hint text pops up and disappears again when you move the mouse, like the help messages in Windows Explorer and other programs, when mouse cursor is being held over a button.
Is there a similar concept in JavaFX (actually, I am using ScalaFX)?
Of course, I can create a new stage without decorations, add some mouse listeners etc., but is it not already available somewhere?
You can use a Tooltip control.
Usage Sample
If you want the tooltip on a Control, for example a button, set the tooltip:
button.setTooltip(
new Tooltip("Button of doom")
);
Otherwise, for other node types like shapes, install the tooltip:
Circle circle = new Circle(15, 15, 42);
Tooltip.install(
circle,
new Tooltip("Circle of light")
);
Tutorial
Oracle have a tutorial dedicated just to Tooltips.
As you can see above, you can set a "graphic" on a tooltip, which can be an image (or any other node), it's pretty flexible.
Tooltip Styling
Tooltip background (with JavaFX CSS)
Other Options
If Tooltip isn't what you are looking for, there are other ways to show popups:
JavaFX 2 custom popup pane
This code creates a GRAPHIC based Tooltip. Take a look at the commented htmlStr..... you can play with it as well as thisToolTip.setStyle..... and see what happens. You can change the styles in htmlStr and the string for setStyle. However I was not able to make the size of the tool tip and the pane match. So there is a border, but I made the color of both background colors to cornsilk. It gives an illusion that there is no border. But it is not true. See the code, if you find it useful, use it.
private Tooltip createToolTip(String htmlStr) {
Tooltip thisToolTip = new Tooltip();
// String htmlStr = "<body style=\"background-color:cornsilk; "
// + "border-style: none;\"> <u><b><font color=\"red\">Click Mouse's right button to see options</font></b></u><br><br>(3) Subha Jawahar of Chennai<br> now # Chennai<br>Female <-> Married <-> Alive<br>Period : 1800 to 2099<br>D/o Dr. Subbiah [2] - <br> <b>Spouse :</b> Jawahar Rajamanickam [7] <br><br><b>Children :</b><br><br>Rudhra Jawahar [9]<br>Mithran Jawahar [10]<br><br></body>\n";
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
webEngine.loadContent(htmlStr);
thisToolTip.setStyle("\n"
+ " -fx-border-color: black;\n"
+ " -fx-border-width: 1px;\n"
+ " -fx-font: normal bold 12pt \"Times New Roman\" ;\n"
+ " -fx-background-color: cornsilk;\n"
+ " -fx-text-fill: black;\n"
+ " -fx-background-radius: 4;\n"
+ " -fx-border-radius: 4;\n"
+ " -fx-opacity: 1.0;");
thisToolTip.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
thisToolTip.setGraphic(browser);
thisToolTip.setAutoHide(false);
thisToolTip.setMaxWidth(300);
thisToolTip.setGraphicTextGap(0.0);
return thisToolTip;
}
Related
Followed the example at https://docs.mapbox.com/help/tutorials/building-a-store-locator/
Worked well. However, the example popup stays in place on mouse exit until your mouseover another marker. Trying to get the popup to disappear on mouseleave.
The popup code from the example is:
/* Create a Mapbox GL JS `Popup`.
**/
function createPopUp(currentFeature) {
var popUps = document.getElementsByClassName('mapboxgl-popup');
if (popUps[0]) popUps[0].remove(0);
var popup = new mapboxgl.Popup({closeOnClick: false})
.setLngLat(currentFeature.geometry.coordinates)
.setHTML('<h3>' + currentFeature.properties.address + '</h4>' +
'<h4>' + currentFeature.properties.sites + '</h4>')
.addTo(map);
}
I think the answer lies in this other post but I dont know how to "move the mouseover declaration" as suggested in the context of my code.
Thanks
I am trying to create a tooltip / popover over a button that has pull-right class set(pull-right basically sets the flow to right). The tooltip/popover crashes when trying to do a placement left. Any suggestions/ help?
/* The widget updateStatusDate is a button that floats right*/
Tooltip tooltip = new Tooltip("Date : " + timeOfOperation + " Comment : " + comment);
setUpdateStatusDate("Last Updated by : " + userName);
tooltip.setWidget(updateStatusDate); tooltip.setPlacement(Placement.LEFT);
tooltip.reconfigure();
Given your code, I have put its simplified version into my project and it works without problems. You can copy it to your project and check if it works:
#Override
public void onModuleLoad() {
// essentials from questioned code
Tooltip tooltip = new Tooltip("text");
Button updateStatusDate = new Button("test button");
tooltip.setWidget(updateStatusDate);
tooltip.setPlacement(Placement.LEFT);
tooltip.reconfigure();
// change style for the rootPanel, so the button flows to the center
// it is just for fast and short code example, do not do this in your regular project
com.google.gwt.dom.client.Style.TextAlign center = TextAlign.CENTER;
RootPanel.get().getElement().getStyle().setTextAlign(center);
//add button
RootPanel.get().add(updateStatusDate);
}
My Bootstrap version is: 2.3.2.0-SNAPSHOT, and my GWT version is 2.5.1.
I want to change background color of a cell in GXT Grid, I am using GXT 3.0 .I have got one link which is related to my query( http://ui-programming.blogspot.in/2010/01/gxt-how-to-set-cell-grid-background.html) but setRenderer method is not present columnConfig in GXT 3.0 .How can i get desired output? pLz help.
Code i have done till now:-
ColumnConfig<Stock, Double> changeCol = new ColumnConfig<Stock, Double>(props.change(), 100, "Change");
changeCol.setCell(new AbstractCell<Double>() {
#Override
public void render(Context context, Double value, SafeHtmlBuilder sb) {
if (value == null) {
return;
}
store.get(context.getIndex());
GWT.log(DOM.getCaptureElement().getId());
String style = "style='background-color: " + (value < 0 ? "red" : "green") + "'";
String v = number.format(value);
sb.appendHtmlConstant("<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>");
}
});
For those that need to change cell colour based on data in the grid, I've just had to do this (GXT 3.1) but unfortunately the solution isn't perfect.
In general, one can do custom cell rendering with ColumnConfig.setCell(MyCell) where 'MyCell' is a subclass of AbstractCell. Unfortunately there is the problem of 'padding' in the host 'div' which isn't coloured. There are a few ways around this...
The simplest way is to:
ColumnConfig.setCellPadding(false)
Render your own coloured divs that fill up the whole cell (with padding if desired)
Unfortunately this doesn't play well with single cell selection (CellSelectionModel). The css class for cell selection is obfuscated so it can't be referenced in other stylesheets. :(
My (ugly) alternative was to render a custom stylesheet that is linked in the module's html page (eg. Main.html). Then I can colour cells using css 'class' instead of 'style' attributes. IE:
Create a custom JSP that renders a stylesheet (content type 'text/css')
Link the stylesheet to the module html (after 'reset.css')
The stylesheet needs to have selector td.someClass (.someClass is not specific enough)
Use Grid.getView().setViewConfig() to supply a GridViewConfig that returns the appropriate class(es)
Unfortunately this requires a good knowledge of CSS rules and also the possible colours need to be known at user login time.
There may be a third way using the style attribute of the 'td' element. Have a look at this issue from Sencha:
http://www.sencha.com/forum/showthread.php?289347-Influencing-cell-td-style-in-a-grid&p=1057079 (work in progress)
Note that other styling options include:
Various ColumnConfig.setXxxClassName()
Various ColumnConfig.setXxxStyle()
I would like to to have a GTK TreeView with a background image as shown in the mockup below.
I have found methods for setting the background color of widgets, but there does not appear to be a method for setting a background pixbuf or other image format.
I'm using Python with PyGTK but an answer in any language with GTK bindings is acceptable.
Mockup of gtkTreeView with background image:
First Attempt
Based on Jong Bor's advice, I tried the following:
style = treeview.get_style().copy()
img_pixbuf = gtk.gdk.pixbuf_new_from_file(image_filename)
img_pixmap = img_pixbuf.render_pixmap_and_mask()[0]
for state in (gtk.STATE_NORMAL, gtk.STATE_ACTIVE, gtk.STATE_PRELIGHT,
gtk.STATE_SELECTED, gtk.STATE_INSENSITIVE):
style.bg_pixmap[state] = img_pixmap
treeview.set_style(style)
At first this didn't seem to have any effect, but upon selecting an item in my TreeView I observed the following:
Part of the background 'shows through' when a row is selected.
(Note that I'm using a background image based on my mockup, except that it has some blue color, for test purposes).
I then activated part of my GUI that clears the contents of the TreeView and redraws it, and observed this:
However as soon as I add something to the TreeView the background disappears, so I'm still not sure if this is going in the right direction.
I suspect that since each cell has a renderer which controls its appearance, you would have to somehow modify the treeview cell by cell.
Anyway, the following code might be worth a try (untested, incomplete code):
# Get the treeview's style
style = treeview.get_style().copy()
# Change the bg_pixmap attribute
# It's an array with one pixbuf for every widget state, so
# you probably want to replace each of the default
# pixmap's with your own image(s)
#
style.bg_pixmap[0] = your_pixmap
style.bg_pixmap[1] = your_pixmap
style.bg_pixmap[2] = your_pixmap
style.bg_pixmap[3] = your_pixmap
style.bg_pixmap[4] = your_pixmap
# Set the modified style
treeview.set_style(style)
The bg_pixmap attribute is documented in the PyGTK reference.
I'm not sure of how the array positions map to widget states. If it is the same as in c++, it will be:
0 - STATE_NORMAL
1 - STATE_ACTIVE
2 - STATE_PRELIGHT
3 - STATE_SELECTED
4 - STATE_INSENSITIVE
Using GTK3 and gtkmm it is possible to use CSS, but the image needs to available as a file or possibly a resources.
Here I assume that the treeview is subclassed:
class MyTreeView : public Gtk::TreeView { .. };
for you treeview set a name and then add a CSS style to it:
MyTreeView::MyTreeView () {
set_name ("MyTreeView");
auto css = Gtk::CssProvider::create ();
auto sc = get_style_context ();
string path_to_img = "my-image.png";
string css_data =
ustring::compose (
"#MyTreeView { background-image: url(\"%1\");"
" background-repeat: no-repeat;"
" background-position: 50%% 50%%;"
" }\n"
"#MyTreeView .hide_bg { background-image: none; }",
path_to_img);
try {
css->load_from_data (css_data);
} catch (Gtk::CssProviderError &e) {
cout "error: attempted to set background image: " << path_to_img.c_str () << ": " << e.what () << endl;
}
auto screen = Gdk::Screen::get_default ();
sc->add_provider_for_screen (screen, css, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
it seems that it is also possible to set the background of the row to transparent by adding:
background: none;
to the CSS.
The background image can then be hidden or shown using:
if (!hide) {
auto sc = get_style_context ();
if (!sc->has_class ("hide_bg")) sc->add_class ("hide_bg");
} else {
auto sc = get_style_context ();
if (sc->has_class ("hide_bg")) sc->remove_class ("hide_bg");
}
In my eclipse RCP application there are a few buttons & few input boxes & this below Text component. My problem is as soon as I press one of the buttons a cursor starts blinking in the below test component. Can you please let me know how to solve this.
I tried:
setting focus to false for Text.
SWT.READ_ONLY for Text .
Code:
Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_NO);
protocolFilterDescription.setCursor(cursor);
Nothing seems to get rid of this unnecessary cursor.
protocolFilterDescription = new Text(parent, SWT.NONE | SWT.READ_ONLY );
FormData protocolFilterDescriptionLData = new FormData();
protocolFilterDescriptionLData.left = new FormAttachment(0, 1000, 650);
protocolFilterDescriptionLData.top = new FormAttachment(0, 1000, 290);
protocolFilterDescriptionLData.width = 450;
protocolFilterDescriptionLData.height = 12;
protocolFilterDescription.setLayoutData(protocolFilterDescriptionLData);
protocolFilterDescription.setForeground(new Color(parent.getDisplay(),
204, 153, 0));
protocolFilterDescription.setBackground(Display.getCurrent()
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
protocolFilterDescription.setFont(new Font(parent.getDisplay(),"Verdana",
6, 1));
protocolFilterDescription
.setText("captured");
You have to set the focus of some other SWT component to true to remove the focus from the Text component.
You'll probably have to do this in an ActionListener.
If you want to completely remove the cursor from the Text control (which implies inability to perform a selection there, etc), try calling setEnabled(false) on it.
Also, such requirement suggests that you maybe don't need Text component at all, and could use Label instead.