JavaFX how to get control characters from TextField - javafx

Currently I have a simple JavaFX application with the following TextField
<TextField id="textfield-EmvTagData" fx:id="textfield_EmvTagData" alignment="CENTER" GridPane.columnIndex="0" GridPane.columnSpan="4" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" />
The user (me in this case) gets a string of data which contains non printable characters (0x1C specifically).
When I later try and execute the following code I get all the text back however the control characters (0x1C) have been removed. My application needs these control characters in order to parse the data. With my old JSwing application JTextField had no problem handling this but I am out of ideas with JavaFX.
Any ideas on how to get all the text in the JavaFX TextField including the control characters that were copied and pasted into it?

Related

Automatically display fxml webview on page start

I am using webview in fxml to display a youtube link in a page, but it is only displayed when the user hovers over it. I couldn't find a way to display it when the page starts automatically.
I am still a beginner and a student in JavaFX.
Movie.fxml:
<HBox layoutX="530.0" layoutY="229.0" prefHeight="379.0" prefWidth="587.0" spacing="3.0">
<padding>
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
</padding>
<children>
<WebView fx:id="SpiderManWebView" onMouseEntered="#SpiderManTrailer" prefHeight="373.0" prefWidth="592.0" />
</children>
</HBox>
Please note I am using other elements not just a webview, I've designed it in scene builder.
MovieController.java:
#FXML
private WebView SpiderManWebView;
#FXML
void SpiderManTrailer() {
WebEngine WebEngine = SpiderManWebView.getEngine();
WebEngine.load("https://www.youtube.com/embed/Lko8OP9_AjQ");
}
According to the youtube documentation:
To make an embedded video autoplay, add "&autoplay=1" to the video’s embed code right after the video ID (the series of letters that follows "embed/").
Sample url from the documentation (not a real playable video link, just a syntax demo):
https://www.youtube.com/embed/D6Ac5JpCHmI?&autoplay=1
If I don't hover, the webview always shows a white box
If you want to load the video and start it playing when the fxml is loaded, then delete the mouse handler and put it’s work (loading the auto play url) into the initialize method.

Xamarin Forms Numeric Keyboard - enable space and dash buttons

I have a requirement where a field in a Xamarin Forms app is allowed to have only numbers, spaces and dashes. Numeric keyboard layout appears to be perfect for this purpose - the only trouble - the space and dash buttons do not appear to work? Is there any way to enable these, specifically on Android - as that is the primary target platform.
Buttons in question are highlighted.
<Entry
x:Name="BarcodeEntry"
Margin="12,0"
HeightRequest="40"
Placeholder="Barcode"
Style="{StaticResource BorderlessEntryStyle}"
Keyboard="Numeric"
Text="{Binding Barcode.Value, Mode=TwoWay}">
Control is bound to this property:
private string _barcode;
public string Barcode
{
get => _barcode;
set { SetProperty(ref _barcode, value); }
For the numberic keyboard, we only have four related InputTypes.
number: A numeric only field.
numberDecimal: Can be combined with number and its other options to allow a decimal (fractional) number.
numberPassword: A numeric password field.
numberSigned: Can be combined with number and its other options to allow a signed number.
For more details about the InputTypes, you could refer to the link below. https://developer.android.com/reference/android/widget/TextView#attr_android:inputType
If you want to use the space and dash buttons, you could use the Telephone keyboard. Or you could create your own custom keyboard.
Custom Keyboard: Numeric keyboard as default on Xamarin.Forms, but allow text (cross platform)

How to wrap long messages using Editor in Xamarin Forms

I am using Editor control and wish to wrap long messages (Like Whatsapp).
I have explored few sites and got nothing . If this feature is not yet in Xamarin Forms , can I know any alternative for the same ?
My XAML
<Editor Grid.Row="0" Grid.Column="0" Text="{Binding TextMessage}"
TextColor="{StaticResource StartColor}" HorizontalOptions="FillAndExpand"
FontSize="14" TextChanged="Editor_TextChanged"
FontFamily="{StaticResource DefaultFont}" IsEnabled="True"/>
OUTPUT-
I would first suggest you to use AutoSize property of Editor, so if you want your editor to automatically resize depending on the text length, you should set it to TextChanges, otherwise set it to Disabled(this is default value).
Next thing, if you know that the Editor will be used for chat, you can also set Keyboard property to Chat:
<Editor Text="Enter text here" AutoSize="TextChanges" Keyboard="Chat" />
If I am not mistaken, The Editor control has a property for this called the AutoSize Property which takes the EditorAutoSizeOption enum as an input. Available options are TextChanges and Disabled.
<Editor AutoSize="TextChanges"...
If for some reason this does not work for you then you can use the solution in this forum discussion. by ionixjunior.
For those who are still facing issues, I have a case where the line does not wrap as long as there is no break line (Enter). Solution was to change parent layout from StackLayout to Grid. With grid, now it works.
If you want the height to change dynamically when you have more lines, you can use the above solution:
AutoSize="TextChanges"

Set placeholder of JavaFX TableView in FXML

I know the following problem is a bit of a luxury problem:
I would like to keep the initialize of my FXML Controller as clean as possible, and therefore I would like to set the placeholder of my TableView in the FXML file (as I think it is the best place to keep it, because it is just a property and in my case also a constant). I already tried to set it in the FXML file like this:
<TableView placeholder="Some text">
This obviously does not work, because the placeholder property expects a Node. That is why I set the placeholder like this in the initialize of the FXML controller:
Label placeholder = new Label();
placeholder.setText("Some text");
tableview.setPlaceholder(placeholder);
This works, but as I said, I would like to manage this from the FXML file only. Some my question is:
How can I set the placeholder from within the FXML file?
Note: please let me know if this i even possible, because when it is not, I will fill a feature request (with a low priority of course!).
Quite simple, just the usual FXML Syntax:
<BorderPane xmlns:fx="http://javafx.com/fxml/1">
<center>
<TableView>
<placeholder>
<Label text="some text"/>
</placeholder>
</TableView>
</center>
Note: Not everything is a primitive value (can be expressed inline) and therefore needs its own element.
I already found the answer using this question: Styling a JavaFX 2 button using FXML only - How to add an image to a button?
The graphic tag triggered the idea to do it like this:
<TableView>
<placeholder><Label text="Some Text"></Label></placeholder>
</TableView>
And luckily it works! I hope I helped some of you too. Also, sorry for asking this question too quickly.

Scene Builder 2.0. FXML import not working

I'm using JavaFX Scene Builder 2.0. version and I would like to import a FXML file under TabPane controller. My idea is that I will have one kind of container FXML file with TabPane and separate FXML files for things that will come inside of tabs. When I try to import FXML file where I have things that I would like to add under one tab, Scene Builder gives error message "Failed to import TabContents.fxml under TabPane". Why it is not possible to import anything under the TabPane? If I import same file directly under root StackPane everything works.
EDIT: While the below works, it is best to add some sort of layout pane (like an AnchorPane) to each tab in your TabPane, select the AnchorPane pane in the hierarchy view on the left and then import your other fxml document into that, as opposed to importing directly into a TabPane (Perhaps if the root node of the document is a Tab it would work?).
Looks like a bug, for now:
Cut your entire document hierarchy
Add an empty stack pane
Include your other FXML file
Paste your document hierarchy into the stack pane
Drag your FXML file into the appropriate place in your hierarchy
Cut your new hierarchy (with your file included)
Delete the now defunct stack pane
Paste your hierarchy back in
And voila, working as intended!
Three simple steps
Add a StackPane to the content area of your Tab, ensuring that it occupies 100% of the area.
Go to the Hierarchy view and select that StackPane you just added.
Include your TabContents.fxml. It should automatically be added to the created StackPane and should display as desired.
Also, to answer your additional question, importing it directly into the TabPane will render it as a Graphic rather than a Node.
just add a new TabPane where you want and then edit your FXML code of the TabPane just added as following:
<TabPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="5000.0" prefWidth="5000.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab closable="false" text="MyTab1">
<content>
<fx:include source="MyTab1.fxml" />
</content>
</Tab>
<Tab closable="false" text="MyTab2">
<content>
<fx:include source="MyTab2.fxml" />
</content>
</Tab>
</tabs>
</TabPane>
adding as many tab you need just adding more 'Tab' tags.
'MyTab1.fxml' and 'MyTab2.fxml' are just fxml files contained in the same folder of the fxml file of the TabPane.
it works for me selecting first the root node in the scene. Then I import de FXML and it is imported hanging from this root node. As the last step, I move the imported FXML to the place I want in the scene.
I realised that the FXML import can also fail when you have another FXML template included in the one you want to import. Something like:
<fx:include source="top-menu-bar.fxml" />
Looks like SceneBuilder doesn't know where is top-menu-bar.fxml. The solution can be to work on the template separately and then adding those includes manually to make it works.
It works for me:
<AnchorPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" >
<children>
<fx:include fx:id="includeID" source="includeSource.fxml" />
</children>
</AnchorPane>
The include file must be include in the children of a pane.

Resources