I try to use a javafx TextFlow to view some styled text. The following code does not do any text styling.
public Node createText(String t,String cls){
Text ret = new Text(t);
ret.getStyleClass().add(cls);
return ret;
}
When I replace Text with Label it works properly, but things like \n obviously do not work anymore. How can I use the Text class with css classes?
EDIT: As requested a short example of my default.css
.defaultElementAttr{
-fx-text-fill:#48a711;
}
-fx-text-fill is a CSS property of Label but it is not a CSS property of Text.
If you want to change the color of a Text object with CSS, use the -fx-fill property:
.defaultElementAttr {
-fx-fill:#48a711;
}
Related
GWT 2.7
How can I set inline text in GWT Button
Button b = new Button("Inline Text");
I don't want text on 2 lines into the button.
You can give the button a width:
button.setWidth("200px");
so that the button has enough space to display the text in one line.
Or you can add a stylesheet with:
button.addStyleName("myStyle");
and this stylesheets contains the line:
.myStyle { white-space: nowrap; }
This should work.
Uglier, but easier ;-) you could replace blanks in your string label with or :
Button b = new Button("Inline Text");
I need to use textarea in my program and I also need it to be read-only.
This is part of my main program where I create textArea:
final TextArea ta = new TextArea();
ta.setMaxSize(9*x, 7*x);
ta.setId("textarea");
ta.setTranslateX(x);
ta.setTranslateY(2*x);
ta.setDisable(true);
This is part of my css file:
#textarea {
-fx-font: 13px "Serif";
-fx-background-color: BEIGE;
}
If I delete the row: ta.setDisable(true); Css works like I want it to work. But after I set disable true, it just makes the textarea transparent, which makes the text really hard to read and the background color is not excatly what I want too.
Is there any other way to set text readonly? Or is there a way to use css after disable. I really need it to be TextArea not Label or any other type. Thank you in advance.
If you do not want the user to make changes to the textarea use the setEditable(boolean) method to false. The same method exists for most editable nodes in javafx(Textfield and PasswordField).
Can I set the font size for string? I want to do text formatting for string, Is it possible in flex?
You can use TextField/UITextField to display formatted text. In both classes you have two options:
You can use setTextFormat() method to format text
You can use htmlText property to display HTML text. These classes don't support all HTML tags. Supported HTML tags are listed here.
If all you need to do is change the font, you can use the StyleableTextField class or the Label and set the . She can set the fontSize style of either class to globally change the font size.
No,
you need to set the font size of label or any text other Text control that you use to show string value.
var str:String = 'This is sample text';
//set in any method
lbl.text = str;
lbl.setStyle('fontSize', 20);
enjoy.
The examples I've seen seem to show how to change the color that shows when the user actually hovers over the textinput field.
However when the validation fails, a generic textInput border qill have a red line over it. My CSS file uses a border skin for the textInput, so I can't see this line.
I was hoping there was a way to highlight the text box when it failed validation, or re-enable the red line feature. I don't want to get rid of my CSS cos it'll totally blow my color-scheme, but any tweak allowing the error line to show would be much appreciated.
This is the CSS:
TextInput, TextArea
{
border-skin: Embed(source='/../assets/images/input_bg.png', scaleGridLeft=8, scaleGridRight=20, scaleGridTop=8,scaleGridBottom=9);
padding-top:2;
padding-left:2;
font-size:11;
}
anything that extends UIComponent (both TextInput and TextArea do) has a style called errorColor. It defaults to red. You can change this to whatever you want.
Additionally, if you've got an image that you are using as a border, you should probably remove the pixels from the middle so that it is an actual border instead of an overlay.
The only way I've managed to find, is that Validator will change the component's borderColor style. I don't think it can be achieved using an image- you'll have to embed the image in a basic GraphicRectangularBorder subclass or similar. You can then add this to your skin class:
override public function styleChanged(styleProp:String):void
{
super.styleChanged(styleProp);
if (styleProp == "borderColor")
{
if (getStyle("borderColor") == getStyle("errorColor"))
{
// show error outline
}
else
{
// hide error outline
}
}
}
I have a tooltip for each datagrid row. Which is fine. I also can style it with with mx:Style which is great.
However, I desire to have multiple styles ie a header and the rest of the text in the tooltip. Is this possible? Or to have htmlText for input?
If you need that you should create your own component implementing mx.core.IToolTip and use it to display the tooltip. Write you own handler for toolTipCreate and in this handler set your own component as the tooltip renderer.
private function createTooltip(e:ToolTipEvent):void {
//CustomToolTip should extend the Canvas and implement IToolTip
var tooltip:CustomToolTip = new CustomToolTip();
//you need to set the tooltip property in order to make your component used for tooltip renderer
e.toolTip = tooltip;
}
<mx:DataGrid id="myDataGrid" toolTip=" " toolTipCreate="createToolTip(event)">