My whole application is right to left for Persian language. I need to show the alerts in right to left.
How could I change the properties of alert dialogue for this purpose?
You should be able to change the nodeOrientation on the dialogPane of the Dialog:
Alert alert = ...
alert.getDialogPane().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
As fabian has suggested below, you could do this simply with
alert.getDialogPane().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
But if someone came in searching for some manual way of doing this (though I don't see why anyone would want to do this), then please find the details below-
I have no knowledge of how the languages Right-To-Left work. But you can TextFlow does provide the option to align text right to left. So this might work, but I am not sure!
Also, the following code snippet does not edit the text in the alert box itself. But it just adds additional TextFlow to the dialog.
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Some title");
Text text = new Text("some right-to-left text here");
TextFlow textFlow = new TextFlow();
textFlow.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
textFlow.getChildren().addAll(text);
alert.getDialogPane().setContent(textFlow);
alert.show();
This is how the dialog box looks, after I added some Google-translated 'Hello World' in Persian. Just did this, so people looking up would directly know if this works or not, rather than having to try it out.
The header text does seem to get in the way. So you can remove it by using-
alert.setHeaderText(null);
EDIT:
Since the buttons are still in English (or Left-Right), here is something you can use, considering you've done the entire application Right-Left, follow same procedure for making the Button texts Right-Left. I wouldn't put time into it, as it is something you already have.
ButtonType okBtn; //make sure this is of type ButtonBar.ButtonData.OK_DONE
ButtonType cancelBtn; //make sure this is of type ButtonBar.ButtonData.CANCEL_CLOSE
Alert alert = new Alert(AlertType.CONFIRMATION,"",okBtn,cancelBtn);
alert.getDialogPane().setContent(textFlow);
alert.setTitle("Some title");
alert.setHeaderText(null);
Optional<ButtonType> result = alert.showAndWait();
You can perform the task if OK button is clicked by processing the result -
Check if result.isPresent() is true and check if result.get() == okBtn
The result of this code (ignore the button texts) -
If this works, then please do let me know. And if it doesn't let me know 'how' its not looking right.
Use:
alert.getDialogPane().getScene().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
instead of:
alert.getDialogPane().setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT);
to make the title bar direction RTL as well.
Related
Please see below image. This pink color pop up appears for a second and that automatically disappears. How to get text from this pop up in selenium.
It wont stay on screen and disappears with in a second.
enter image description here
It wont stay on screen and disappears with in a second.
It seems your problem is that the popup is not staying on screen for enough time to let you identify html elements to use in your selenium script.
If I'm correct, you can press F8 whenever this message appears to pause the chrome window and then normally identify elements from this message. (using F12: Dev tools)
Depending on the message box, you can use:
If it is alert/popup. You can use:
Alert alert = driver.switchTo().alert();
String text = alert.getText();
If its html just another html element, like div or td. you can use following:
String text= driver.findElement(By.xpath(elementXpath)).getText();
Hope this helps!
I have a display text area in my JavaFX app.
It has several methods for appending strings to it.
What I want is for any newly appended text to have some kind of feedback so the user is more visually aware of the new text being displayed.
Ideally what I would like is one of the following, but am very open to other suggestions:
The appended text is 'typed out' as if someone were typing it into the display text area itself. Or..
Some kind of highlighting of the new text as it appears.
Although again, I'm open to suggestions!
Thank you.
As suggested in Highlighting Strings in JavaFX TextArea, you can select the new text.
Assuming the text area is not editable, and you are only ever appending to the end of the existing text, you can do:
textArea.textProperty().addListener((obs, oldText, newText) -> {
if (newText.length() > oldText.length()) {
Platform.runLater(() ->
textArea.selectRange(oldText.length(), newText.length()));
}
});
If your text area is editable, or you are using it more generally, then you can do something similar each time you append text. For example:
String message = ... ;
textArea.positionCaret(textArea.getLength());
textArea.appendText(message);
textArea.extendSelection(textArea.getLength());
Maybe try to use RichTextArea (https://github.com/TomasMikula/RichTextFX), then is many possibilites to show your text in different ways.
I'm trying to create one search toolbar that appears inside the letters hidden stick. when I press the hidden letters that when the bar disappears and there's no hiding the letters that appear. I've tried to capture events keyPressed entering the search bar, but I do not really feel comfortable with that way. if anyone has a better way, I hope everyone helps do.cam Thanks!
photo illustration
Check out the Text Prompt.
You can control when the prompt disappears. You can also control the color and style of prompt.
The Text Prompt uses a DocumentListener and a FocusListener to determine when the prompt should be displayed.
You can use the default settings with a single line of code:
JTextField textField = new JTextField(10);
TextPrompt tp7 = new TextPrompt("First Name", textField);
I've created a checkbox skin for libgdx Scene2d but the problem that there is no space between my checkbox and the text label , here is my code for the checkbox :
final CheckBox vSyncCheckBox = new CheckBox("vSync", skin);
vSyncCheckBox.setChecked(vSync());
vSyncCheckBox.getCells().get(0).size(30, 30);
and in the table layout i tried to use spaceRight(10); but nothing happens :
table.add(vSyncCheckBox).top().expandY().spaceRight(10);
here is the image on what the checkbox looks like for the moment:
Like you can see the checkbox and Vsync are stack together any help on how to provide some space between them ?
This is how you set space between the check box and the text label.
final CheckBox vSyncCheckBox = new CheckBox("vSync", skin);
vSyncCheckBox.getLabelCell().padLeft(10);
This is how I solved my similar problem:
table.add(yourButton).padLeft(Distance).OTHER_STUFF;
Next time please refer to the Wiki table page to solve any problems of or relating table layout
If you have any problems in understanding the concept turn on debugging
table.setDebug(true);
If your check box and your label is one single item, you can just simply put some space " vSync" in your declaration of the object instead of "vSync".
Could you please post the whole code of that table? It might be not working because of other settings made to the table.
Also, it can be helpful to activate debug mode by using
table.setDebug(true); // turn on all debug lines (table, cell, and widget)
Source: https://github.com/libgdx/libgdx/wiki/Table#debugging
i got the following java code
Icon icoR = new ImageIcon("src/resources/Republica.png");
Icon icoI = new ImageIcon("src/resources/Imperio.png");
JButton botRep = new JButton("Jedi", icoR);
JButton botImp = new JButton("Sith", icoI);
Object[] options = {botRep, botImp};
//Object[] options = {"Jedi","Sith"};
int i = JOptionPane.showOptionDialog(
null,
"Question","Title",
JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE,
null,options,options[0]);
System.out.println(i);
and im trying to retrieve the selected value from the optionDialog with icon buttons. Problem is, that althought dialog and buttons themselves are properly shown, whenever the buttons are clicked.. nothign happens, and the println statement isnt executed... until i click on the X to close the dialog, and regardless of what i have clicked before.. an 1 is printed as result. Oddly enough, if i change the options array to the regular (text only) one that appears commented in the code, the dialog behaves as one would expect returning the 0-based index of the chosen option. Any hints on what could be wrong here?
thanks in advance
It works if you just pass the Icons, the option pane will create the buttons for you:
Object[] options = {icoR, icoI};
So I guess if you pass the buttons it assumes that you will handle the closing of the option pane yourself.
As a work around you can use the Compound Icon class to create an Icon containing text and your image.
You might also want to use the Text Icon which you can also find from the above link. When you create the TextIcon you will probably need to use:
setFont( UIManager.getFont("Button.font") );
to set the font of the TextIcon to be the same as the button.