In my GWT app I want to indicate the fields as required. Please advise how do I do that?
If i just add a * in the label text then it is not very well noticeable as it is of the same color as the label text and also aligned to the label rather like a superscript character.
I don't know if applying style sheet can make it work? Any other web 2.0 ideas which do not involve a lot of work?
Currently, it's displayed as
Label fullName = new Label("Full Name*");
The simplest way is
String strReqLabel = "<span style=\"color: #DC143C;\">*</span>"
Label reqLabel = new Label(strReqLabel + " " + "First Name");
Just separate the * from the label, to another label:
Label label = new Label("Full name");
TextBox tb = new TextBox();
Label reqLabel = new Label("*");
reqLabel.setStyleName("red_label");
then on the war/app.css crete a new item
.red_label {
color: red;
font-size: 8pt;
overflow: hidden;
}
Smething like this should work.
Alternatively,
Suffix the label with * mark - so that who are really cautious of filling the form will observe it and do the needful. For those you are not cautious, after submitting the form,
you can think of making the outline in red color. This way, you need not make the form too flashy at initial look.
So I did it as:
public HorizontalPanel createLabel(String name){
HorizontalPanel hPanel = new HorizontalPanel();
hPanel.add(new Label(name));
Label star = new Label("*");
star.setStyleName("req-label");
hPanel.add(star);
return hPanel;
}
and css as:
.req-label{
color: #FF0000;
font-weight: bold;
}
Related
I'm looking for an easy way to make some letters in a label bold.
I have a string like this:
String r = "y = "+output0+" "+output1+"sin(x) "+output2+"cos(x)";
and a label:
Label s = new Label(r);
and I need to make the "y" and "sin(x), cos(x)" bold. I tried using HTML, but it didn't work (maybe i was using it wrong). If I set font for that label, then the whole label is bold (including those outputs) which is not what I need.
You can use html style in JLabels and in some other Java components. If you start your text with <html> and end it with </html>, the html code in your JLabel will be rendered.
This should resolve your issue:
JLabel myLabel = new JLabel();
// The following line is required to make this JLabel's text not bold as JLabel's text is bold be default.
myLabel.setFont(myLabel.getFont().deriveFont(Font.PLAIN));
myLabel.setText("<html><strong>y</strong> = " + output0 + " " + output1 + "<strong>sin(x)</strong> " + output2 + "<strong>cos(x)</strong></html>");
Try using HTML (you have to start the string with <html> and end it with </html>):
new Jlabel("<html>Normal text. <strong>This is bold.</strong></html>")
Explanation! <html> tells Java to render HTML (Hyper Text Markup Language), and <strong> tells HTML that the text inside is of strong importance, normally represented in bold.
As it says on the tin.. I cannot get a label's text to wrap. Essentially I am building like a comments panel, user enters a comment and its displayed with timestamp etc.
I want the labels to both display with ContentMode.PREFORMATTED but also wrap.
The layouts of which contain the label are fixed width (100%) as is the label obviously by default, from what I have readin the book of vaadin what I am doing should work?
here is my code snippet:
VerticalLayout container = new VerticalLayout();
rootLayout.addComponent(container);
VerticalLayout comment = new VerticalLayout();
container.addComponent(comment);
Label createdByLbl = new Label(entity.getManagedMetadata().getAttrValue("createdBy") + " said:");
createdByLbl.setId("conversation.comment.username." + repositoryUID);
createdByLbl.setStyleName("conversation-comment-username");
Label createdDateLbl = new Label(entity.getManagedMetadata().getAttrValue("createdDate"));
createdDateLbl.setId("conversation.comment.createddate." + repositoryUID);
createdDateLbl.setSizeUndefined();
String text = entity.getDataNode().getAttrValue("text");
Label textLbl = new Label(text, ContentMode.PREFORMATTED);
textLbl.setId("conversation.comment.text." + repositoryUID);
comment.addComponent(createdByLbl);
comment.addComponent(textLbl);
comment.addComponent(createdDateLbl);
comment.setExpandRatio(createdByLbl, 0.2f);
comment.setExpandRatio(textLbl, 0.7f);
comment.setExpandRatio(createdDateLbl, 0.1f);
Note the container is also wrapped by CssLayout (rootLayout), which is full sized.
I want the textLbl as seen above to display as formatted should the user enter text on separate lines themselves and wrap if they have entered a long paragraph comment.
Here is a picturing showing my dilemma.
Any help would be appreciated.
Thanks,
Try with css.
For example:
textLbl.addStyleName("wrapLine");
Css:
.wrapLine{
word-wrap: break-word; /* IE */
white-space: -moz-pre-wrap; /* Firefox */
}
I've got problem with displaying full content of Label in VStack.
In my VStack are few Labels one of them has content that contains a lot of text and some images, all of it is just html. It causes two little different bugs.
In firefox it cuts bottom part of that Label, but it works when FF windows is resizing, in Chrome it cuts the same part but resize window doesn't help (whole content of label is still inside).
Could anyone help me ?
private Label createBodyLabel(String body) {
Label bodyLabel = new Label();
bodyLabel.setWidth100();
bodyLabel.setMargin(25);
bodyLabel.setBorder("0px solid #808080");
bodyLabel.setBackgroundColor("#FFFFFF");
bodyLabel.setContents(body);
return bodyLabel;
}
Try it again after moving the styles in CSS file instead of directly settting it in code.
CSS:
.myLabel{
width: 100%;
margin: 25px;
border: 1px solid #808080;
background-color: #FFFFFF;
}
JAVA:
private Label createBodyLabel(String body) {
Label bodyLabel = new Label();
bodyLabel.setStyleName("myLabel");
bodyLabel.setContents(body);
return bodyLabel;
}
I never suggest you to set the style in code itself but still if you are interested then tye with Style that is obtained by calling Element#getStyle().
I have a TreeEditor and some text in its first column. I need to append some text to it using a label or string. In addition, I want to change the color of the appended string to green. I tried to do it with this code, but it isn't working:
Label label = new Label(this.tree ,SWT.RIGHT);
label.setFont(new Font(getSite().getShell().getDisplay(), ("Hello"), 18,
SWT.BOLD));
label.setText("hello:));
label.pack();
treeItem.setText(1, hi + " " + label.getText());
How could I accomplish this?
you might want to look at org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider
How to write text in two rows inside a JLabel ( It doesn't work with \n ) ?
Try to make it like this: JLabel myLabel = new JLabel("<html>this is line1<br>this is line2</html>");
JLabel label = new JLabel("<html>Two<br/>lines</html>");
See How to Use HTML in Swing Components
go for "<html> one <br/> two </html>"
jLabel.add("<html>a<br/>b</html>");
Here is also solution if you want to center the two lines in the jlabel.
JLabel label = new JLabel("<html> <center> line1 </center> <center> line2 </center> </html>");