ClassCastException in Vaadin scrollIntoView - java

I try to use UI.getCurrent().scrollIntoView() to scroll to a label, but I get a casting exception. The method scrollintoView requires a com.vaadin.ui.Component, but my label is a com.vaadin.flow.component. What is the difference between a component in the com.vaadin.ui and com.vaadin.flow.component packages?

com.vaadin.ui.Component is Vaadin 7 & 8. com.vaadin.flow.component.Component is Vaadin 10 and newer.
Having both in the same project implies that you are using Multiplatform Runtime. In that context, you can use ui.scrollIntoView(component) for Vaadin 7/8 components whereas Vaadin 10+ 23.1+ components have that as a feature of the component itself as component.scrollIntoView().
Edit: component.scrollIntoView() was introduced only in Vaadin 23.1. For older versions starting from Vaadin 10, you can use this workaround: component.getElement().executeJs("var el = this; setTimeout(function() {el.scrollIntoView();}, 0);");.

Related

Vaadin 8. Resource cannot be resolved

I tried to add an overlay plugin. https://vaadin.com/directory/component/overlays
I have a problem with image overlay. Im getting that error:
The type com.vaadin.terminal.Resource cannot be resolved.
It is indirectly referenced from required .class file
problem is with this line:
io.setImage(res);
how can I fix it? I put icon-new.png to the class package folder and added into maven overlays plugin
My code:
final ImageOverlay io = new ImageOverlay(button);
Resource res = new ClassResource(this.getClass(), "../icon-new.png");
io.setImage(res);
io.setComponentAnchor(Alignment.TOP_LEFT); // Top left of the button
io.setOverlayAnchor(Alignment.MIDDLE_CENTER); // Center of the image
io.setClickListener(new OverlayClickListener() {
public void overlayClicked(CustomClickableOverlay overlay) {
Notification.show("ImageOverlay Clicked!");
}
});
layout.addComponent(io);
io.setEnabled(true);
I need to achive that on the button will show up an overlay. If the user clicked on this button and added a new content something like taht show up on the button
That's because it's compatible with Vaadin 6 only as it's indicated in the add-on page:
If you scroll to the comments section, someone is suggesting a fork of the add-on compatible with Vaadin 7, but I could not see anything related to 8:
HI ALL! You can find version 1.1.3 for Vaadin 7.6 here: https://github.com/Haulmont/vaadin-overlays/releases
YURIY ARTAMONOV
Add-ons that are compatible with multiple Vaadin versions, indicate this explicitly, and usually (but not necessarily... dev's choice) have different version numbering, eg: 1.x for Vaadin 6, 2.x For Vaadin 7, 3.x for Vaadin 8, etc:
Either way, clicking on the link for a specific Vaadin version, will select the latest add-on release compatible with it. Or, if you select an add-on release from the drop-down, the Vaadin version compatible with it will be updated accordingly.
Edit after update
You can use a regular button + the predefined BUTTON_ICON_ALIGN_RIGHT Valo style. From the javadoc:
/**
* Align the icon to the right side of the button caption. Can be combined
* with any other Button style.
*/
public static final String BUTTON_ICON_ALIGN_RIGHT = "icon-align-right";
Please note that for the best UI result, I've used 24x24 icons, but depending on your requirements you can tweak your theme for the size you need. Also if you don't have icons and don't want to spend money or time buying or creating your own icons, you can use the existing Vaadin Font Icons (list of icons and matching java enum)
public class ButtonWithIconOnTheRightComponent extends VerticalLayout {
public ButtonWithIconOnTheRightComponent() {
// text filed to specify icon URL
TextField urlField = new TextField("Icon URL", "http://files.softicons.com/download/toolbar-icons/status-icons-set-by-iconleak/png/16x16/30.png");
// button which updates its icon using the URL specified in the text field above
Button button = new Button("Update icon", event -> event.getButton().setIcon(new ExternalResource(urlField.getValue())));
// use valo style to align icon to the right
button.addStyleName(ValoTheme.BUTTON_ICON_ALIGN_RIGHT);
// add components to the UI
addComponents(urlField, button);
setSpacing(true);
}
}

Trying to style SwingNodes in JavaFX with GTKLookAndFeel freezes application

We have a Java application that used Swing, but we are migrating it to JavaFX. Therefore, we wrap the old Swing code into SwingNodes and replace them step-by-step.
Before migrating, the Swing application used com.sun.java.swing.plaf.gtk.GTKLookAndFeel as look-and-feel (default on Ubuntu). We used following code to set it (if available):
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if (info.getClassName().equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel")) {
UIManager.setLookAndFeel(info.getClassName());
}
}
This worked fine. Yet, after switching to JavaFX, the call to UIManager.setLookAndFeel() freezes the application, and nothing happens. The manual setting of the look-and-feel is needed since we want to still style the Swing components that have not been migrated to JavaFX based on the GTKLookAndFeel.
Further info: This only does not work with com.sun.java.swing.plaf.gtk.GTKLookAndFeel, since it works when using javax.swing.plaf.metal.MetalLookAndFeel, javax.swing.plaf.nimbus.NimbusLookAndFeel or com.sun.java.swing.plaf.motif.MotifLookAndFeel.
What can we do to make it work with GTKLookAndFeel to style our Swing components in the SwingNodes?
Gui components need to be updated into gui threads.
Try one of the following:
SwingUtilities.invokeLater(() -> {
//commands
});
javafx.application.Platform.runLater(() -> {
//commands
});

Nested Vaadin applications

Is it possible to nest one Vaadin application into another? I want to implement a portal with application A and embed several applications into that portal.
I can have multiple Vaadin applications next to each other by calling vaadin.initApplication multiple times with different IDs as target elements:
vaadin.initApplication("target-element-id",{
"theme": "mytheme",
"versionInfo": {
"vaadinVersion": "7.5.1",
"atmosphereVersion": "2.2.7.vaadin1"
},
"widgetset": "de.test.widgetset",
"vaadinDir": "http://localhost/VAADIN/",
"browserDetailsUrl": "http://localhost/service1",
"serviceUrl": "http://localhost/service1",
"debug": true,
"standalone": false,
"heartbeatInterval": 300
});
But as soon as I specify an element as target that is already inside a Vaadin UI, I get the following error:
java.lang.AssertionError: A widget that has an existing parent widget may not be added to the detach list
Sounds like you want a Vaadin application as a portlet. The Vaadin docs contain a chapter for that: https://vaadin.com/docs/-/part/framework/portal/portal-overview.html
Information on Java portlets:
https://en.wikipedia.org/wiki/Java_Portlet_Specification
You may have a look at Liferay:
https://en.wikipedia.org/wiki/Liferay

How to get checkBox readOnly state in Gxt 3.1.1 like there is isReadOnly() method in gxt 3.0.0?

I am trying to implement something like the below code in my projeect using Gxt 3.1.1 :
CheckBox checkBx = new CheckBox();
checkBx.setReadOnly(False);
System.out.println(checkBx.isReadOnly());
While this snippet will ru nwell on Gxt 3.0.0 but with 3.1.1 its showing the last line as unsupported. Also there is no method to get ReadOnly state. How can I implement any method for such functionality ?
This is an API change from 3.0.3 (See https://docs.sencha.com/gxt/3.1/announcements/release_notes.html):
Backwards incompatible - CheckBox and Radio no longer support setting
the readOnly attribute (only supported by text and passwords inputs)
You can use setEnabled() and isEnabled() instead.

How to alter WM_CLASS value in a Java GUI application based on Swing or NetBeans Platform?

All Swing/NetBeans-based Java GUI applications seem to have the same WM_CLASS value:
WM_CLASS(STRING) = "sun-awt-X11-XFramePeer", "java-lang-Thread"
This parameter can be viewed by issuing xprop command and pointing to the window. The practical purpose of customizing it is to let Mac-like docks (AWN, for example (and, perhaps, Ubuntu's Unity)) distinguish the application windows and group them under the application's pinned launcher icon. For this to work StartupWMClass parameter is to be set accordingly in the .application file in ~/.local/share/applications or /usr/share/applications. Needless to say, AWN (and analogues) get confused in case more than one application uses the same string for WM_CLASS.
This blog post found the field in Toolkit that controls it, named awtAppClassName. It suggests using reflection to modify it:
Toolkit xToolkit = Toolkit.getDefaultToolkit();
java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
awtAppClassNameField.setAccessible(true);
awtAppClassNameField.set(xToolkit, applicationName);

Categories