This is how I set my tooltips:
if(Globals.isShowTooltips()) {
locale = new Locale(Globals.getGuiLanguage());
bundle = ResourceBundle.getBundle("bundles.lang", locale);
btnSettingsApply.setTooltip(
new Tooltip(bundle.getString("btnSettingsApplyt")));
btnSettingsOk.setTooltip(
new Tooltip(bundle.getString("btnSettingsOkt")));
btnSettingsCancel.setTooltip(
new Tooltip(bundle.getString("btnSettingsCancelt")));
}
How can I hide tooltips? It seems to me that there isn't a straight-forward approach for this.
Any help is appreciated!
For Controls
Controls have a setter for tooltips. So for controls, use that.
To set the tooltip on a control:
btnSettingsOk.setTooltip(new Tooltip("OK Button"));
To remove the tooltip on a control:
btnSettingsOk.setTooltip(null);
For Nodes which are not Controls
Layout panes, shapes and other nodes do not have a setter for tooltips (because tooltips are classified as controls and the JavaFX developers wanted to avoid a dependence of the general scene graph nodes on the controls package). However those nodes can still work with tooltips using the static install and uninstall methods.
This is pretty much Ikallas's answer, though I would only advise using it when the node type in question does not supply an explicit setTooltip method - even though it will also work for controls. The set method on controls is simpler to use because the control stores a reference to the Tooltip, whereas, for an static uninstall, your application is responsible for keeping the reference to the tooltip so that it can later remove it.
To set the tooltip on a Node which is not a control:
Tooltip okTooltip = new Tooltip("OK Button");
Tooltip.install(btnSettingsOk, okTooltip)));
To remove the tooltip from a Node which is not a control:
Tooltip.uninstall(btnSettingsOk, okTooltip);
OK, just found answer to my own question :)
Tooltip.install(btnSettingsOk, new Tooltip(bundle.getString("btnSettingsOkt"))); //This is for showing
Tooltip.uninstall(btnSettingsOk, new Tooltip(bundle.getString("btnSettingsOkt"))); //This is for disabling
If there is some better way I would like to know about it ;)
Related
What is the exact use of ColumnViewerTooltipSupport? I know that it provides tooltip support for ColumnViewers but does it mean that it provides tooltip for treeViewers? How can I use this feature to provide tooltip support individually different tooltips for my each tree item when the mouse hovers over each item? Do I require a MouseListener for this or does the ColumnViewerTooltipSupport class provide it by default? Can someone please help me out here as I'm relatively new to SWT concepts.
My tooltip has multiple lines, How can I wrap the text and display it neatly? It seems like ColumnViewerToolTipSupport class does not wrap the tooltip text if the text is too long. I would like to use a tooltip window with a vertical scroll bar just like the InformationControl Windows in eclipse? If something like eclipse is not possible then just a tooltip window with wrapped up text.
Please show me an example snippet?
ColumnViewerToolTipSupport adds support for individual tooltips to TableViewer and TreeViewer (and other ColumnViewers), you enable this using:
ColumnViewerToolTipSupport.enableFor(viewer);
The support expects that the label provider(s) for the viewer are based on CellLabelProvider (or one of its subclasses).
CellLabelProvider has getToolTipImage, getToolTipText, getToolTipBackgroundColor, getToolTipForegroundColor, getToolTipFont and getToolTipShift methods that you can override to control the tooltips.
Note: All this is JFace code not pure SWT
I am designing a Jframe using netbeans. I do have few questions.
Can we create a label for a field in a desired location(For eg.,we have a field named height, I need to display a label below it indicating height is in cm) conditionally?
Can we disable a field based on a condition?(by disable I mean it shouldn't be displayed in my frame)
Can someone suggest me whether we can achieve them through some examples.
Tried this, after some helpful suggestions
private void englishRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JLabel userlabel;
if (englishRadioButton.isSelected())
{
userlabel = new JLabel("Inches");
userlabel.setBounds(311, 59, 64, 36);
//userlabel.setLocation(307,55);
//userlabel.setSize(70,40);
userlabel.setForeground(Color.green);
userlabel.setText("Inches");
userlabel.setVisible(true);
System.out.println(englishRadioButton.getBounds());
inchesTextField.setVisible(true);
}
}
The textfield is visible only when I click the English radio button,at the same time I need to get a label but it's not displayed with the above code. Can I know where I am going wrong?
Please see the attached screenshots
When English button is clicked, I need a label beneath the second textfield as inches, I am disabling the text field when Metric is displayed. I am able to achieve the later one but not the former one
Thanks!!
Yes, relative placement of components is easily achieved with use of layout managers.
Yes, all components have a setEnabled(...) and a setVisible(...) method either of which can be called at any time during a program's run. The former helps you activate/inactivate components and the latter helps make them visible/invisible. If you want to swap complete "views", use a CardLayout.
Regarding:
Can someone suggest me whether we can achieve them through some examples.
Please, you first as I strongly believe that the onus of effort here should be yours, the questioner's, since you're the one asking the questions, and the one with the most to learn by coding as much as possible. Let's see your attempts and we can help you with them. Otherwise the best examples are to be found at the Swing Tutorials.
For links, please look here: Swing Tag Info.
Edit
You ask:
I tried the above posted code,conditionally disabling the text field works well but getting a label doesn't work. Can you please suggest on that?
I don't see you adding your JLabel to any component. If you are going to create a component on an event, you must add it to a component whose ancestor hierarchy eventually reaches a visible top-level component such as a JFrame. Then after adding a component to a container (say a JFrame), you must call revalidate() on the container to have its layout managers re-layout its components, and then repaint() to repaint any "dirty" pixels.
I again will re-iterate that you're far better off not using null layout and absolute positioning, but rather using layout managers and relative positioning. If you want a label with and without visible text, it's often best to add an empty JLabel to the GUI on GUI creation, and just set its text when needed, as long as the label is located somewhere that allows its text to shrink and expand.
Also, as to your current problem, you might wish to show a picture of what you're trying to achieve, and what you're getting. Or if you can't post a picture here yet, post a link to an image or images you've created, and then we'll post it for you.
Both Eclipse an Netbeans provide a vertical points of interest highlighter next to document scroll bars, which appears to be a part of an extended JScrollPane or is simply a standalone custom component.
I've marked it on the picture below (Netbeans and Eclipse version, in that order).
It highlights lots of different things and represents a flat view of the entire document.
What is this area/component called in general?
I've been looking around on pointers on how to implement such a thing in swing or abuse an existing implementation to my liking but I don't even know what to search for. Both implementations of this thing appear to be quite similar, so I'm hoping they are based on the same piece of code.
It's an extend JScrollPane which has implemted some kind of column footer.
The default JScrollPane provides row and column headers by default, check out How to use scroll panes for more details
Try taking a look at JideScrollPane from jidesoft
Eclipse just calls these vertical rulers (they are implemented with SWT in Eclipse).
I want to create panel object (working as a kind of navigation bar) shared between pages. I want to add buttons dynamically, so it's important to me that all pages share the same object.
However when I add the panel to second page it disappears from the first one! Why is it so?
And maybe any tips how to deal with it? :)
The Vaadin component hierarchy allows for one component to be at one place at a time. In other words, you can't have the same Component instance added to two places at the same time.
The best solution would be to move your panel so that the panel is never replaced, only the surroundings. If that's impossible, you need to just recreate the controls for each page.
If your controls are stateful, remember that Properties can be shared between Fields, and all classes extending AbstractFields are Properties, so you can do stuff like
TextField tf1 = new TextField();
layout1.addComponent(tf1);
TextField tf2 = new TextField();
tf2.setPropertyDataSource(tf1);
layout2.addComponent(tf2);
This way your two textfields are backed up by the same Property. So, after the value has changed, your two textfields have the same value.
I would suggest you take a look at FlexTabSheetNavigationFeeder a component that, to my understanding, is used for creating a universal navigation menu connecting view/content to each of the buttons/tabs of the component.
I use a common library of the Vaadin framework and we have component called SFlexTabSheet doing exactly what it sounds that you want to do.
I have a problem with rendering nodes in JTree. When node's font is changed and node's text gets wider that way then node's text is cut and end of text replaced with dots.
How to tell the JTree then that it should widen area to render tho whole node.
Thank you for help
You can use custom renderer and set to the component (JLabel) something like this
final Dimension size = label.getPreferredSize();
label.setMinimumSize(size);
label.setPreferredSize(size);
or just set text like this
setText("<html>" +valueText+"</html>")
Sounds like the trigger of the font change happens under the feet of the tree: internally, the ui delegate does lots of size caching which must be updated on any change which effects the cached sizes. That's done automatically on changes to the treeModel, to relevant expansion state and some visual changes to the tree itself.
So the basic question is: what triggers the change of the font? If it's some change of the model/nodes, the model implementation is incorrect in not firing an appropriate TreeModelEvent, the obvious solution would be to fix that :-) If it's something outside the model, the solution depends on the details of your context, nothing generally applicable.
Size caching
The JTree uses a renderer to render nodes. The renderer is the same renderer for all OSs, so the differnt lookings are inside ComponentUIs. JTree uses by default a JLabel to paint nodes, so its the JLabel's size wo guides us to cut the text using ....
Lets make a short excourse: Swing has differen LookAndFeels for different Operation Systems, they are detached from the components in UI-Classes like the BasicLabelUI (and this is the source of your problem). BasicLabelUI caches the size of the label to prevent recalculation if no changes has made. So BasicLabelUI did not clear the cache of theese old size values. BasicLabelUI do clear the cache if he gets informed about any changes.
The question is, why does the BasicLabelUI did not get informed about changes? Well, if you modify/expand/rename the Tree programatically you must tell the ComponentUI to drop that cache!
You lucky, you do not need to write much code because a genius already wrote something for you, the creators of the TreeUI-class Rob Davis and Scott Violet wrote startEditingAtPath and stopEditing.
Example
TreeUI ui = tree.getUI();
for (TreePath treePath : selectionPaths) {
ui.startEditingAtPath(tree, treePath);
}
tree.setSelectionPaths(selectionPaths);
tree.expandPath(expandPaths.getSelectionPath());
ui.stopEditing(layer);
Call your TreeModel's reload()