Add labels dynamically on Groupbox but only half text is displaying - groupbox

I am trying to add dynamic labels on groupbox, but my text size which I also created dynamically is only showing half of it on group box.
This is my simple code:
private void AddLabels()
{
List<Label> labels = new List<Label>();
groupBox1.Controls.Clear();
Label l = new Label();
l.Font = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.Serif), 30, FontStyle.Bold);
l.Text = "Hello World";
l.Parent = groupBox1;
l.BringToFront();
labels.Add(l);
}
As you notice on my code, my Font Size is 30, but when I run this, only "Hello" text is showing and only half of "Hello" is showing. The word "World" is not showing also.

Just in case you encounter the same problem. I already figured it the day I posted my question and I want to answer this just in case someone is looking for an answer.
Just adjust your label font size and everything will work fine.

Related

Bold Text Parts in ControlsFX Notification

I'm trying to write bold text inside the body of a Notification.
Notifications.create()
.title("My Title")
.text("This is <bold>text</bold>")
.showInformation();
As far as I can tell there's only the .text("my text") method to set the text of a Notification.
However I'd like to use a TextFlow in there to modify certain parts of a text.
I've also tried to use CSS for this but that only lets me change to overall appearances of the Notification as setting specific text through CSS is explicitly not supported.
My question now is: Is there a way to style parts of a text inside a Notification differently?
Got it working now.
The solution is to use .graphic(Node node). If you still want to display an Image at the left side you need to put everything in a Pane and add some padding.
I yoinked the original image from here.
BorderPane borderPane = new BorderPane();
borderPane.setLeft(new ImageView(Controller.class.getResource("/dialog-information.png").toExternalForm()));
TextFlow textFlow = new TextFlow();
textFlow.setPadding(new Insets(15, 0, 5, 5));
Text text1 = new Text("This is ");
Text text2 = new Text("bold");
text2.setStyle("-fx-font-weight: bold");
textFlow.getChildren().addAll(text1, text2);
borderPane.setRight(textFlow);
Notifications.create()
.title("My Title")
.graphic(borderPane)
.hideAfter(Duration.seconds(10))
.show();
It is important to use .show() and not .showInformation/Error/Warning() because that would override the BorderPane.
Result:

JavaFx TextFlow does not resize on GridPane on change of value

I have a TextFlow in a GridPane, when I change its value to a wider one it does not increase its width accordingly on display but truncates. I am a newbie at Java and I've probably missed something simple.
Initial value is built as follows;
TextFlow mhText = new TextFlow();
// Loop to build TextFlow
for(Card c : myGame.me.playerHands.get(0).handCards) {
Text text = new Text(c.cardText(false) + " ");
if(c.redSuit()) {text.setFill(Color.RED);}
mhText.getChildren().add(text);
}
playerGrid.add(mhText, 1, pgRow)
Then later it is rebuilt...
mhText.getChildren().clear();
for(Card c : myHand.handCards) {
Text text = new Text(c.cardText(false) + " ");
if(c.redSuit()) {text.setFill(Color.RED);}
mhText.getChildren().add(text);
}
Result screenshot
You can just see from the screenshot that only a dot from the additional 3rd 'card' is showing, I think due to truncation. I've tried using setPrefWidth and setMinWidth without success.
I can solve the problem by removing and re-adding the TextFlow on the GridPane,
playerGrid.getChildren().remove(mhText);
playerGrid.add(mhText, 1, myHandRow);
but I would be surprised if this is the right way, any advice is welcome.

Codename One add icon to title

I am trying to add an icon to the title/ title bar.
Changing the title itself with code works fine :
setTitle("Testing");
Yet I can't figure out a way to add an icon to it. Here is what I have tried, with no avail:
Image img = Image.createImage("/kalender.png");
getTitleComponent().setIcon(img);
FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_SEARCH, "TitleCommand", 3);
getTitleComponent().setIcon(icon);
Any help would be appreciated.
setTitleComponent will solve it as soon in below
FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_SEARCH, "TitleCommand", 3);
Label title = new Label(icon);
**setTitleComponent(title);**
[EDIT]
**getToolbar().setTitleComponent(titles);**
This works for me:
Form form = new Form(BoxLayout.y());
Image icon = FontImage.createMaterial(FontImage.MATERIAL_CAKE, "TitleCommand", 5).toImage();
Label tittleButton = new Label("Tittle", icon, "Label");
form.getToolbar().setTitleComponent(tittleButton);
form.getToolbar().setTitleCentered(true);
form.show();

How to make Flex Spark Label to be auto resized?

I'm creating the Label component like this
var label:Label = new Label();
label.text = "some text";
label.styleName = "someStyle";
addChild(label);
But it stay invisible until I explicit set the width and height.
How can I make the label to be auto resized according to it's text?
I've found the answer to my question here
The solution is to call a measureText() function for the label
var lineMetrics:TextLineMetrics = label.measureText(label.text);
label.width = lineMetrics.width;
label.height = lineMetrics.height;
I've also noticed the above answer doesn't seem to work with spark components. This does however work for me.
label.width = label.measuredWidth;
label.height = label.measuredHeight;
You should be able to use label.percentWidth = 100; to allow the label to automatically grow with the text. If you want it to stay on a single line, you'll also want to set the maxDisplayedLines = 1; property as well.
You may also want to use addElement(label) instead of addChild(label).

How do I Print a dynamically created Flex component/chart that is not being displayed on the screen?

I have a several chart components that I have created in Flex. Basically I have set up a special UI that allows the user to select which of these charts they want to print. When they press the print button each of the selected charts is created dynamically then added to a container. Then I send this container off to FlexPrintJob.
i.e.
private function prePrint():void
{
var printSelection:Box = new Box();
printSelection.percentHeight = 100;
printSelection.percentWidth = 100;
printSelection.visible = true;
if (this.chkMyChart1.selected)
{
var rptMyChart1:Chart1Panel = new Chart1Panel();
rptMyChart1.percentHeight = 100;
rptMyChart1.percentWidth = 100;
rptMyChart1.visible = true;
printSelection.addChild(rptMyChart1);
}
print(printSelection);
}
private function print(container:Box):void
{
var job:FlexPrintJob;
job = new FlexPrintJob();
if (job.start()) {
job.addObject(container, FlexPrintJobScaleType.MATCH_WIDTH);
job.send();
}
}
This code works fine if the chart is actually displayed somewhere on the page but adding it dynamically as shown above does not. The print dialog will appear but nothing happens when I press OK.
So I really have two questions:
Is it possible to print flex components/charts when they are not visible on the screen?
If so, how do I do it / what am I doing wrong?
UPDATE:
Well, at least one thing wrong is my use of the percentages in the width and height. Using percentages doesn't really make sense when the Box is not contained in another object. Changing the height and width to fixed values actually allows the printing to progress and solves my initial problem.
printSelection.height = 100;
printSelection.width = 100;
But a new problem arises in that instead of seeing my chart, I see a black box instead. I have previously resolved this issue by setting the background colour of the chart to #FFFFFF but this doesn't seem to be working this time.
UPDATE 2:
I have seen some examples on the adobe site that add the container to the application but don't include it in the layout. This looks like the way to go.
i.e.
printSelection.includeInLayout = false;
addChild(printSelection);
Your component has to be on the stage in order to draw its contents, so you should try something like this:
printSelection.visible = false;
application.addChild(printSelection);
printSelection.width = ..;
printSelection.height = ...;
...
then do the printing
i'm not completely sure, but in one of my application I have to print out a complete Tab Navigator and the only method i have found to print it is to automatically scroll the tabnavigator tab in order to show the component on screen when i add them to the printjob.
In this way they are all printed. Before i created the tabnaviagotr scrolling the print (to PDF) result was a file with all the pages of the tab but only the one visible on screen really printed.

Resources