I want to set line-height for RichTextArea component in GWT. How could I do it?
I've added initialization handler to my custom RichTextArea and external css richtextarea.css:
addInitializeHandler(new InitializeHandler() {
public void onInitialize(InitializeEvent ie) {
Document document = IFrameElement.as(getElement()).getContentDocument();
BodyElement body = document.getBody();
HeadElement head = HeadElement.as(Element.as(body.getPreviousSibling()));
LinkElement styleLink = document.createLinkElement();
styleLink.setType("text/css");
styleLink.setRel("stylesheet");
styleLink.setHref("richtextarea.css");
head.appendChild(styleLink);
}
});
Add the following class to your application css
.gwt-RichTextArea
{
line-height: 5px;
}
No need to add this class explicitly to your richtextarea as the GWT component listens to this css Class by default.
Related
I'm trying to add an external web widget from a weather website. It gives me somethink like this:
<div id='cont_5caab8f298a3d34d53973f2d8906d1f7'><script type='text/javascript' async src='https://www.tiempo.com/wid_loader/5caab8f298a3d34d53973f2d8906d1f7'></script></div>
I've tried creating a HTML widget with that code and adding it to my panel, but it doesn't show.
The embed code you have been given only works when it is included in the HTML file. It doesn't work when added dynamically. For example, if you open an empty HTML file in a web browser and run:
document.body.innerHTML += "<div id='cont_5caab8f298a3d34d53973f2d8906d1f7'><script type='text/javascript' async src='https://www.tiempo.com/wid_loader/5caab8f298a3d34d53973f2d8906d1f7'></script></div>";
in the developer (F12) console, you will see that the external content doesn't get loaded. This is because scripts will not automatically be executed when added in this way.
You don't need to execute this external script, however. All it does is create and insert an iframe, and set some attributes and styling. If we look at the source code of the script, we can translate it into a GWT equivalent.
Embed JS script:
conte = document.getElementById("cont_5caab8f298a3d34d53973f2d8906d1f7");
if (conte) {
conte.style.cssText = "width: 176px; color: #868686; background-color:#FFFFFF; border:1px solid #D6D6D6; margin: 0 auto; font-family: Roboto;";
elem = document.createElement("iframe");
elem.style.cssText = "width:176px; color:#868686; height:200px;";
elem.id = "5caab8f298a3d34d53973f2d8906d1f7";
elem.src = "https://www.tiempo.com/getwid/5caab8f298a3d34d53973f2d8906d1f7";
elem.frameBorder = 0;
elem.allowTransparency = true;
elem.scrolling = "no";
elem.name = "flipe";
conte.appendChild(elem);
}
GWT equivalent:
public class Hello implements EntryPoint {
public void onModuleLoad() {
Panel root = RootPanel.get("main"); // replace with your Panel
//This doesn't work:
//HTML embed = new HTML("<div id='cont_5caab8f298a3d34d53973f2d8906d1f7'><script type='text/javascript' async src='https://www.tiempo.com/wid_loader/5caab8f298a3d34d53973f2d8906d1f7'></script></div>");
//This does:
Frame embed = new Frame("https://www.tiempo.com/getwid/5caab8f298a3d34d53973f2d8906d1f7");
embed.setStyleName(""); // remove GWT styling. You could add your own CSS class here.
embed.getElement().setAttribute("style", "width:176px; color:#868686; height:200px;");
embed.getElement().setAttribute("frameborder", "0");
embed.getElement().setAttribute("scrolling", "no");
root.add(embed);
}
}
You can use an IFrame element to load external content.
final Frame frame = new Frame("url");
frame.addLoadHandler(new LoadHandler() {
#Override
public void onLoad(LoadEvent event) {
// do stuff here
}
});
RootPanel.get("mydiv").add(frame);
Note though, that you won't be able to interact with the external content due to Cross site scripting.
I want to disable the mouse highlighting of rows of a celltable.
This celltable is not a selectionmodel so I dont want the rows to get highlighted while mouse over event.
We are basically extending the CellTable Resources which contain the CssStyles of the CellTable so that we can custom define our own css styles. for more css classes check this link
public interface IMyResources extends CellTable.Resources {
interface IMyStyle extends CellTable.Style {
}
#Override
#Source({ CellTable.Style.DEFAULT_CSS, "MyStyleSheet.css" })
IMyStyle cellTableStyle();
}
MyStyleSheet.css CSS :
.hoveredRow {
background-color: none; //or just remove this but keep the class declaration
}
JAVA //dont forget add the resource.
CellTable<dataType> myCellTable = new CellTable<dataType>(15, GWT.create(IMYResources.class));
I have a case where I want to append
white-space: nowrap;
to the style of each cell in my CellTable. Currently it applies to all tables, but it would be nice to know both have to apply it for a specific CellTable, and all CellTables.
CellTables have their own CssResource. To override this style applied to all cells in a cellTable, create a new css file :
/* Incremental changes from CellTable.css */
.cellTableCell {
white-space: nowrap;
}
Then create your own CellTable.Resources interface :
public interface TableResources extends CellTable.Resources {
/**
* The styles applied to the table.
*/
interface TableStyle extends CellTable.Style {
}
#Override
#Source({ CellTable.Style.DEFAULT_CSS, "MyOwnCellTableStyleSheet.css" })
TableStyle cellTableStyle();
}
Finally, when creating your cellTable, use the constructor that lets you specify which Resources to use
CellTable<Object> myCellTable = new CellTable<Object>(15, GWT.create(TableResources.class));
For a working example, look at the Expenses sample provided in the GWT SDK.
Or you could do this the easy way:
CellTable<YourObj> yourTable = new CellTable<YourObj>();
yourTable.getElement().getStyle().setWhiteSpace(WhiteSpace.NOWRAP);
No css files, no weird boilerplate code.
I'd like to use the following in UIBinder, so that I can programmatically set the href of the link in my code.
<g:HTMLPanel>
<g:Anchor ui:field="link">
<g:InlineLabel ui:field="firstName"/>
<g:InlineLabel ui:field="lastName"/>
</g:Anchor>
</g:HTMLPanel>
When I try this I get:
ERROR: Found widget in an HTML context Element <g:InlineLabel ui:field='firstName'> (:7).
How can I embed widgets inside an anchor? Previously I've resorted to using:
<a id="myAnchor">
etc...
</a>
And then manipulating the DOM in my code to set the HREF, but that's ugly. Is there a better way?
The class below acts exactly like a SimplePanel (i.e., you can put an widget in it), but uses an "a" instead of a "div". If you need more widgets just put another panel in it.
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.SimplePanel;
public class Link extends SimplePanel {
public Link() {
super(DOM.createAnchor());
}
private void setHref(String href) {
getElement().setAttribute("href", href);
}
private String getHref() {
return getElement().getAttribute("href");
}
public void setTarget(String frameName) {
getElement().setAttribute("target", frameName);
}
}
It is better to use a Panel (Flow or Horizontal) and add click handlers to the panel to simulate a link. Anchor, Button and similar widgets will not allow child tags inside them.
In my page I have a Gxt ContentPanel with a white background. However, when the user mouses over the Header of the ContentPanel, I would like the background to change colors.
I tried achieving this by using the protected addStyleOnOver method of Gxt Component, but it doesn't have any effect. Is there anything else I need to do to use that methods (I'm already sinking the ONMOUSEOVER and ONMOUSEOUT events), or a better way to change the background?
you can do this using below code its working
ContentPanel contentPanel = new ContentPanel();
contentPanel.setStyleName("background");
and write below code in your css
.background:hover .x-panel-body {background-color: red !important;}
i'm not sure if this works, but you can test it...
final ContentPanel test = new ContentPanel();
test.getHeader().addListener(Events.OnMouseOver, new Listener<BaseEvent>() {
#Override
public void handleEvent(BaseEvent be) {
test.getHeader().setStyleName("your_new_style");
// or test.setStyleName("your_new_style");
}
});
You could simply add a style to the header, then add some css to change the color.
test.getHeader().addStyleName("my_style")
# css
my_style:hover { background-color: yellow; }
This is a bit trickier if you want to change the bg of the whole ContentPanel during onMouseOver of the header, in which case, add the mouse over event to the header where handle event adds style to the content panel (or content panel body depending on what you want), then add the appropriate styles to you css.
# css
my_style { background-color: yellow; }