GWT - split string according to the chars physical length (not number of chars) - string

I have a gwt button that has a fixed size.
I want to present a text on it, and if that text exceeds the button length, I need to cut it short and put "..." in the end. I use the following code now:
if(name.length() > 11){
//limiting the size of the text presented on the button
name = name.substring(0,10)+"...";
}
I have a list of such buttons, and this approach causes that not all button's text have the same size.
The problem is, for example, that 10 chars of "!" are much shorter than 10 chars of "A".
Can anyone help me with a way to solve this issue?
Thanks!

Fast answer. Try ussing HTML5/CSS3 property. It does exactly that:
http://www.w3schools.com/cssref/css3_pr_text-overflow.asp
If you need to do that for non-CSS3 browsers you'll need to make some kind of fake. Maybe setting a button div content, with overflow-hidden, and placing a floating "..." to the right. But it's more difficult...

You could add a style-class to all those buttons and fix their size.
Should be something like this:
First, add the style-class to each button:
Button button = new Button();
button.addStyleName("buttonSizeStandard");
Then add a matching style in the css file:
.buttonSizeStandard{
width: 200px; //change 200 to whatever
}

Related

ipywidgets Textarea height='auto' does not work

I am using ipywidgets to create a Dashboard with voila
I have a Textarea as follows:
comm_text = widgets.Textarea(value='',
placeholder='OK',
description='',
style=style,
layout=widgets.Layout(height="auto", width="auto"))
what I pretend with height="auto" is that when entering lines in textarea the text box expands vertically accordingly. (I want to have all the text visible)
It actually does not happend.
As you can see in the screenshot I introduced 8 lines but the textarea does not expand along.
Is that at all possible?
If not, what does actually height="auto" stand for?
If you change
layout=widgets.Layout(height="auto", width="auto")
for
layout=widgets.Layout(height="100%", width="auto")
It will resize to display all the text that it had on the value (default value for the Textarea).
However it won't grow as you type. I don't remember any textarea that does that on webpages.
One more thing. If you are using grids, with height="auto" and you resize the Textarea (dragging by the corner), it will resize other related elements of the grid.
That won't happen if you use height="100%"
The parameter height='auto' sets the CSS of the widget to 'auto'. But it has no effect for a textarea, because the number of rows are hard-coded. Jason Grout speaks of this in this Github post.
If you want a growing text area, you could use this workaround:
def get_bigger(args):
comm_text.rows = comm_text.value.count('\n') + 1
comm_text = Textarea(value='',
placeholder='OK',
description='',
rows=1,
layout=Layout(width="auto"))
comm_text.observe(get_bigger, 'value')
comm_text
Disclaimer: I don't know if this behavior is useful. You will give up control how big the textarea can get.

How to span a number of columns, regardless of the nested grid context?

I need to set the width of an element that is used in various places in my fluid Susy layout. The parent element is not always the same width, but I want this element to always have the same width relative to the page width.
Example:
In a 12-column grid, a news article sometimes spans 12 columns, sometimes 6. Editors are able to add a <blockquote> in the news article text. I want a blockquote to always be 3 columns wide (relative to the full page), regardless of its context (12 or 6 columns).
Of course if this was a grid with fixed column widths it would be easier, but I'm looking for a fluid, percentage-based solution.
PS. I am willing to use Susy 2 alpha if that makes it easier to solve the problem.
You would do this the same way in Susy 1 or 2, though it's always more fun in 2. :)
The issue isn't really related to anything specific about Susy, it would be a problem in any fluid CSS situation. You can only solve it if you have a hook for knowing which context you are in. At that point, you can solve it from either end. Something like this:
blockquote {
#include span-columns(3);
.narrow & { #include span-columns(3,6); }
}
There really isn't any way to do it without the hook. CSS doesn't have element-queries (and isn't likely to any time soon, for the reasons given in that article).

How to wrap af:inputFile text name?

I am using JDeveloper 11.1.2.3.0,
I have an inputFile component in my page that takes its text value from the name of some components. The problem is that that when the text is long it gets displayed all there and may even occupy the whole window. Is there any possibility to wrap this text value in this case?
I don't think <af:inputFile> has a labelStyle attribute:
You can try adding the CSS in the component's inlineStyle or contentStyle
<af:inputFile inlineStyle="word-wrap:break-word;" />
It depends if the very long text is in the content or the label of the field.
If this doesn't do the trick, you can try creating a custom skin and customizing the label or content style via the adf style selectors: af|inputFile::content , af|inputFile::label.
Btw, you need to check if word-wrap works on all browsers you're targeting.
You can try setting the labelStyle attribute of the <af:inputFile> component to wrap the contents of the label. I am not sure of the CSS style attribtue information for it, but searching on the net I found word-wrap:break-word;.
I too had this problem with af:inputFile.
Just give contentStyle="width:200px" it will solve the issue.
we can adjust the width accordingly.

How to get the effect of 'user-select: text' in css3?

The validator at http://jigsaw.w3.org/css-validator/ says that the value 'text' for 'user-select' is not valid. For a css rule with this code in it:
user-select: text;
the validator says:
text is not a user-select value : text text
Presumably this is because of this behavior, specified at (the outdated) http://www.w3.org/TR/2000/WD-css3-userint-20000216#user-select:
This property is not inherited, but it does affect children in the
same way that display: none does, it limits it. That is if an element
is user-select: none, it doesn't matter what the user-select value is
of its children, the element's contents or it's childrens contents
cannot be selected.
Also, I only see the attribute value 'text' specified in that out-of-date css3 doc from w3.org:
http://www.w3.org/TR/2000/WD-css3-userint-20000216#user-select
and not in the latest one: http://www.w3.org/TR/css3-ui/
Additionally, searching 'whatwg.org' yields nothing.
Any ideas if 'user-select: text' is valid css3, and if not, what should be used instead?
This would be used, for example, when overriding 'user-select: none' rules applied to containers of text and ancestor containers.
You are getting this wrong. user-select:text doesn't mean it would select text only. It's default value of user-select property. W3C describe it this way:
The element's contents follow a standard text content selection model.
And Also MDN syas something same:
-moz-none The text of the element and sub-elements cannot be selected,
but selection can be enabled on sub-elements using
-moz-user-select:text .
So I don't think this should prevent selecting images or boxes.
As far as I know user-select:text is useful when you have user-select:none for most or all of your elements and you have a textbox or text area that is kind of output and you want it be selectable for copying and pasting.
It seems if you use -webkit- prefix it works for me. I'm sure it works with -moz- prefix too. Test this fiddle in your browser. I don't know why user-select:text is not working on my Chrome 13 Mac?

LWUIT display bold text + normal text

I need to display some Rich-Text in LWUIT.
I was thinking of HTML Component, but I can't get linewrapping there - probably an error on my side.
Another idea would be to use TextAreas or Labels and do it manually.
I'd need the possibility to have bold words in a non bold sentence.
Hello, this is a bold. <- This dot shouldn't be bold.
Is there a way I can achieve that? I think I only can use one Font per Component...
Use a Container with flow layout and just place labels into it. This is what the HTML Component does internally.
Try com.sun.lwuit.html.HTMLComponent class. Use it like,
HTMLComponent htmlComp = new HTMLComponent(null);
htmlComp.setBodyText("<b>Hello</b>, this is a <b>bold</b>. <- This dot shouldn't be <b>bold</b>.");
form.addComponent(htmlComp);
This component will allow you to use html tags inside text. For more information, refer this link: HTMLComponent

Resources