Displaying single pane alert in javafx - javafx

I am using the following code to show an error alert :
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setContentText(resourceBundle.getString("loginError"));
alert.showAndWait();
This alert looks a little weird to me as there are two panes the top one just showing Error and a cross button and the bottom one showing the text incorrect username or password
Is there some way to get rid of the top pane?
As the header pane already showing Error and cross button I don't see the reason for the next pane to show Error and a red cross button

To remove the header try,
alert.setHeaderText(null);
To remove the icon try,
alert.setGraphic(null);
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setContentText("Incorrect Username or Password");
alert.setHeaderText(null);
alert.setGraphic(null);
alert.showAndWait();

Alert alert = new Alert(Alert.AlertType.NONE);
This will remove the header alert.

Related

Popup Hide Show

I want to create show and hide a alert bar using (alert) button click, If i click that alert button it needs to show what is that alert & again I click that button it needs to be (Hide) visibility gone...I want to switch that visibility thats all.
How to do this in android kotlin, I am new to this field, Plz help me..
This is my code
// for alert popup
binding.alertImage.setOnClickListener {
binding.alertImage.setVisibility(View.INVISIBLE);
binding.scrollText1.visibility = View.VISIBLE
}

How to play a video in a alert using JavaFX?

I'm trying to play a video in a alert dialog using JavaFX. The problem is that I can't find how to display the video or more how to insert it in the alert ?
Here is my alert code
MediaPlayer player = new MediaPlayer( new Media(getClass().getResource("video.mp4").toExternalForm()));
MediaView mediaView = new MediaView(player);
private void alert(){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Don't be a fool");
alert.setHeaderText("");
alert.setContentText("Do you really think your time is correct ?");
Optional<ButtonType> result = alert.showAndWait();
}
An Alert extends from Dialog, which means you can customize its DialogPane. If you want to add a video to your alert, the best place is probably the dialog pane's content. But note that setting the content will replace the contentText (which you set in your example code):
In addition to the header and content properties, there exists header text and content text properties. The way the *Text properties work is that they are a lower precedence compared to the Node properties, but they are far more convenient for developers in the common case, as it is likely the case that a developer more often than not simply wants to set a string value into the header or content areas of the DialogPane.
This means, if you still want to display "Do you really think your time is correct?", you'll have to add your own Label to the content as well. For example:
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Don't be a fool");
alert.setHeaderText("");
Label label = new Label("Do you really think your time is correct?");
VBox content = new VBox(10, label, mediaView);
content.setAlignment(Pos.CENTER);
alert.getDialogPane().setContent(content);
alert.setOnShowing(e -> player.play());
alert.showAndWait();

Prevent expanded notification view

I have this code to style my notification:
remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification);
mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(R.drawable.ic_stat_notification);
mBuilder.setCustomContentView(remoteViews);
mBuilder.setOngoing(true);
mBuilder.setCategory(NotificationCompat.CATEGORY_PROGRESS);
mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
mBuilder.setShowWhen(false);
mBuilder.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
mBuilder.setAutoCancel(true);
As you can see I haven't defined an expanded view for the notification by calling mBuilder.setCustomBigContentView(). Nevertheless the notification is showing with a arrow pointing up as if my notification was expanded. How can I prevent that arrow from showing?
Remove line
mBuilder.setStyle(new NotificationCompat.DecoratedCustomViewStyle());

How do I create a JavaFX Alert with a check box for "Do not ask again"?

I would like to use the standard JavaFX Alert class for a confirmation dialog that includes a check box for "Do not ask again". Is this possible, or do I have to create a custom Dialog from scratch?
I tried using the DialogPane.setExpandableContent() method, but that's not really what I want - this adds a Hide/Show button in the button bar, and the check box appears in the main body of the dialog, whereas I want the check box to appear in the button bar.
Yes, it is possible, with a little bit of work. You can override DialogPane.createDetailsButton() to return any node you want in place of the Hide/Show button. The trick is that you need to reconstruct the Alert after that, because you will have got rid of the standard contents created by the Alert. You also need to fool the DialogPane into thinking there is expanded content so that it shows your checkbox. Here's an example of a factory method to create an Alert with an opt-out check box. The text and action of the check box are customizable.
public static Alert createAlertWithOptOut(AlertType type, String title, String headerText,
String message, String optOutMessage, Consumer<Boolean> optOutAction,
ButtonType... buttonTypes) {
Alert alert = new Alert(type);
// Need to force the alert to layout in order to grab the graphic,
// as we are replacing the dialog pane with a custom pane
alert.getDialogPane().applyCss();
Node graphic = alert.getDialogPane().getGraphic();
// Create a new dialog pane that has a checkbox instead of the hide/show details button
// Use the supplied callback for the action of the checkbox
alert.setDialogPane(new DialogPane() {
#Override
protected Node createDetailsButton() {
CheckBox optOut = new CheckBox();
optOut.setText(optOutMessage);
optOut.setOnAction(e -> optOutAction.accept(optOut.isSelected()));
return optOut;
}
});
alert.getDialogPane().getButtonTypes().addAll(buttonTypes);
alert.getDialogPane().setContentText(message);
// Fool the dialog into thinking there is some expandable content
// a Group won't take up any space if it has no children
alert.getDialogPane().setExpandableContent(new Group());
alert.getDialogPane().setExpanded(true);
// Reset the dialog graphic using the default style
alert.getDialogPane().setGraphic(graphic);
alert.setTitle(title);
alert.setHeaderText(headerText);
return alert;
}
And here is an example of the factory method being used, where prefs is some preference store that saves the user's choice
Alert alert = createAlertWithOptOut(AlertType.CONFIRMATION, "Exit", null,
"Are you sure you wish to exit?", "Do not ask again",
param -> prefs.put(KEY_AUTO_EXIT, param ? "Always" : "Never"), ButtonType.YES, ButtonType.NO);
if (alert.showAndWait().filter(t -> t == ButtonType.YES).isPresent()) {
System.exit();
}
And here's what the dialog looks like:

Clear data after submit button from text box and labels

i have a web form that asks for the mobile number and id, if the id or mobile are incorrect. the web page will display an error label, after this error label if i entered a correct information this form will be not visible anymore and a new div will be visible with another display. so here the problem is when the customer enters the new info after a wrong info, if he clicks back the label is still appearing and text box 2, i have set these elements to:
lblfailedresponce.Text = "" // 1rsst text box
txtMobilePhone.Text = "" //2nd text box
TransactionID.Text = "" // label
but it didn't work and they still appear. so what is the code in the submit button that i have to do to clear the cache or the fields from the invisible form?
Use the following code
txtMobilePhone.Text = String.Empty;
lblfailedresponce.Text = String.Empty;
<script>
$(document).ready(function() {
// clear error label if the user clicks on the text box.
$('#txtMobilePhone').click(function(){
if('#lblfailedresponce').val()!=null)
{
$('#lblfailedresponce').val()='';
}
$('#txtMobilePhone').val()='';
$('#TransactionID').val()='';
});
$('#TransactionID').click(function(){
if('#lblfailedresponce').val()!=null)
{
$('#lblfailedresponce').val()='';
}
$('#txtMobilePhone').val()='';
$('#TransactionID').val()='';
});
});
</script>
This is a script that will serve the purpose. Kindly use this at the page bottom and see how it works.Hope this will help you.
I assume the element Id of the text boxes and its name are same. Kindly change it if its otherwise.
If it is a caching issue then you could add Response.Cache.SetCacheability(HttpCacheability.NoCache) to your page load. That will make it so the browser will not cache the page.
Another option is that you could set your error label to visible=false and then make it visible in the code that checks your error. But then the next load after that the error label will not show as visible.

Resources