JavaFX HTML styling (or equivalent) labels - styles

In Swing, it was trivially easy to style a JLabel using HTML - you simply used the HTML you wanted as the text for the label, and it was rendered appropriately.
In JavaFX this isn't available, but we can set the style of a particular label (or node in general) using the setStyle() method.
However, using this approach it's not obvious how to set part of a label to be a certain style, for instance the equivalent of:
JLabel label = new JLabel("<html>Part of this <b>text is b</b>old and part isn't.</html>");
What would be the easiest way to achieve something like the above?

You can try using TextFlow to combine different styled text nodes like
TextFlow textFlow = new TextFlow();
Text first=new Text("Part of this ");
first.setStyle("-fx-font-weight: regular");
Text second=new Text("text is b");
second.setStyle("-fx-font-weight: bold");
Text third=new Text("old and part isn't.");
third.setStyle("-fx-font-weight: regular");
textFlow.getChildren().addAll(first, second, third);

Pseudo-selectors could have been a work-around but unfortunately most of them are not supported yet - http://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html#introlimitations. As for Rich Text Support in controls, they will be provided by JavaFX8 - https://bugs.openjdk.java.net/browse/JDK-8091709.

Related

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.

Orchard CMS: Add a stylesheet to a page

Setup:
I am using Orchard CMS 1.6.
I have a site where I need to be able to set the background color of the whole page. Ie, I need to style the body tag.
I could use the LayoutSelector module and have distinct layouts. However, the only difference in each layout is that the background-color rule for the body tag is different. So it seems a very un-dry way of doing things.
I can't find any way to make Vandelay.Classy add a distinct id or class to the body tag (it adds, as I understand it) an id or a class to the outer tag of a content type. In my case, that isn't the body tag.
So that is no good, I really do need to customize the body tag.
How to do this?
Note:
I need 3 different background colors. I also have a two column layout and a three column layout. [I use (a modified version of) the layoutSelector module to achieve this.] So to have 3 different colors of background, and I used layouts to achieve this, I would need 6 different layouts: TOTAL overkill.
There must be a better way...
From any cshtml file, you should be able to access the Layout shape. From pretty much anywhere else, you can still get to the Layout shape through WorkContextAccessor. Once you have a reference to the Layout shape, you can do Layout.Classes.Add("the-class-you-want").

Find UIWebview's content height before loading it

I have a couple of custom cells and web views inside each of these cells. Now,my requirement is to find the height of the HTML string to be loaded on the webview, then based on this change the Custom cell height and the webview height.
I am aware that the document's height can be found in the -webViewDidFinishLoading delegate, but in my app i have a lot of cells and webviews inside each of these cells, so i feel that the app would slow up while scrolling and making unnecessary callbacks
At present i am doing this which gives me the string height.
-(float)getDynemicHeight:(NSString *)pstrText
{
CGSize constraint = CGSizeMake(683,600);
CGSize size = [pstrText sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height, 44.0f);
if (height>400) {
return 400;
}
return height;
}
This however causes a problem as even <div> elements are considered as string and hence a larger value of height is returned
In iOS 6, if you just want to show styled text (not text with images mixed in or something like that), you might like to use NSAttributedString instead of a web view. It allows you to create text with different styles in different stretches of text, paragraph margins, etc. etc. Its metrics are well defined and it comes with measurement methods. Simple UIView subclasses such as UILabel can now display an attributed string. Or you can just draw it yourself, directly into the interface.
http://www.apeth.com/iOSBook/ch23.html#_attributed_strings
If you can't do that, then what you're trying to do is basically impossible. You don't know how the Web view will draw a piece of complex HTML until it has drawn the complex piece of HTML. You will simply have to change your app's architecture. For example you could draw all the Web views way ahead of time so you have the needed info during table-dataSource time.

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

Possible to implement an XForms Color Picker? (Not using Orbeon)

I'm looking to implement an XForms Color Picker/Selector/Control (you know where it shows boxes or shades of colors in a dropdown type control).
Is it possible to do this in XForms (without using Orbeon; I am using XSLTForms)? Is so, how is it implemented, or can anyone point me to (simple) code examples that do?
The best approach will depend on what XForms implementation you are using. If Orbeon Forms, I would create an XBL component that encapsulate the YUI color picker:
http://developer.yahoo.com/yui/colorpicker/
If you're using the Firefox plugin exclusively, then you can create new xform extension components by wrapping any combination of HTML, JavaScript, XForms and XUL widgets in XBL.
This is probably the best resource I've found for Mozilla XBL xforms extensions:
https://developer.mozilla.org/en/XForms/Custom_Controls
In your case, probably the most efficient way to get this working would be to wrap the XUL colour picker component in XBL, ( https://developer.mozilla.org/en/XUL/colorpicker ) then write a little bit of JavaScript to link the picker's "onchange" event back to your model.

Resources