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
Related
I try to make a label to display "You Win" and add it to winStage, but I cannot manage to display the label correctly on winStage. Some words don't show on the screen, and if I downscale further than 0.044f, the String disappears. when I add font.setUseIntegerPositions(false) to my code, the font shows correct, but the wrong label also shows. Is there a way to get this work? (hide the wrong label or get the label shows correctly), code uses Kotlin, but very similar to java
YUW N is the wrong label I want to remove, the correct "You Win" only shows when I add font.setUseIntegerPositions(false)
here's the relevant code part
private val winViewport = StretchViewport(mainStage.width, mainStage.height)
val winStage = Stage(winViewport, winBatch)
var font = BitmapFont()
var labelStyle = Label.LabelStyle()
labelStyle.font = font
labelStyle.fontColor = Color.RED
var label2 = Label("YOU WIN", labelStyle)
label2.setBounds(0f, winStage.height*2/3, winStage.width*1, winStage.height/6)
label2.setFontScale(0.07F) // 0.07f
font.setUseIntegerPositions(false)
label2.setWrap(false)
winStage.addActor(label2)
winStage.act(delta)
winStage.draw()
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 have tried many different tutorials and none have worked this is what I have. Any help?
UIManager.put("OptionPane.font", new FontUIResource(new Font("Press Start 2P", Font.PLAIN, 11)));
if (questionNumber == questions.size()) {
triviagui.questionFrame.setVisible(false);
JOptionPane.showMessageDialog(null, "Your score for this level was : " + levelScore + " out of 10. \n Your total score is " + triviagui.totalScore, "Scores", JOptionPane.INFORMATION_MESSAGE, pokeballIcon);
}
this is how I change my font in a JLabel, so maybe it is any help?
message = new JLabel(textMessage);
// create bigger text (to-times-bigger)
Font f = message.getFont();
message.setFont(new Font(f.getName(), Font.PLAIN, f.getSize()*2));
// put text in middle of vertical space
message.setVerticalTextPosition(JLabel.CENTER);
You just take the font from your label, and reset the font as you like.
Maybe you can do the same with your JDialog?
I found a working answer here: formatting text in jdialog box
this could be a method called by the actionListener of a button:
public void openPopUp(){
String t = "<html>The quick <font color=#A62A2A>brown</font> fox.";
JOptionPane.showMessageDialog(null, t);
}
Gives you this result:
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;
}