I have a JavaFX application, but when people try to run it nothing happens because they got no JavaFX on their system, because they are using OpenJDK for example.
What can I do to inform people about the problem?
Best way would be to have an Alert informing the user about that, is there a way to do this with basic Java functionality?
You can use a Swing App to start and check if Java FX is avalaible like this:
private static boolean isJavaFxAvalaible() {
try {
ClassLoader.getSystemClassLoader().loadClass("javafx.application.Application");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
If this is true, just load your Main JavaFX, here's an example:
Launch JavaFX application from another class
hope this can help you.
Related
I am following Respond to system theme change to respond to OS theme in xamarin form app. The app supports both Dark and Light themes with AppThemeBinding. I am not using any custom themes. I am following OS themes only. So I have a Switch which the user would prefer to enable Dark Mode (same as OS). The link suggests the following code to enable specified Mode (e.g Dark Mode).
Application.Current.UserAppTheme = OSAppTheme.Dark;
The above code does nothing, but if I write the above code in App.cs after InitializeComponent() The app changes to Dark Mode.
I Then realized to restart the MainActivity in Android which I did with the help of Dependency.
[assembly: Dependency(typeof(AndroidThemeChanged))]
public class AndroidThemeChanged : ITheme
{
public void OnThemeChanged()
{
var activity = CrossCurrentActivity.Current.Activity;
var intent = GetLauncherActivity();
activity.Finish();
activity.StartActivity(intent);
}
public static Intent GetLauncherActivity()
{
var packageName = AndroidApp.Context.PackageName;
return AndroidApp.Context.PackageManager.GetLaunchIntentForPackage(packageName);
}
}
and Calling it
if (Device.RuntimePlatform == Device.Android)
DependencyService.Get<ITheme>().OnThemeChanged();
Is there any way to update application theme irrespective of OS theme (Dark/Light) without restarting the MainActivity?
My bad, I guess I was wrong. The code in my question works as expected. I don't need to have that Android Service to restart activity.
Calling below from any where changes the theme to Dark irrespective of OS theme.
Application.Current.UserAppTheme = OSAppTheme.Dark;
I guess you don't have to restart the MainActivity. As per the documentation here we can react to the theme changes using the Application.Current.RequestedThemeChanged event.
Please make sure to follow the AppThemeBinding markup extension as per the documentation here.
Try the below code.
Application.Current.RequestedThemeChanged += Current_RequestedThemeChanged;
private void Current_RequestedThemeChanged(object sender, AppThemeChangedEventArgs e)
{
if (e.RequestedTheme == OSAppTheme.Dark)
Application.Current.UserAppTheme = OSAppTheme.Dark;
else
Application.Current.UserAppTheme = OSAppTheme.Light;
}
I hope that helps.
I have implemented a clickable Frame in Xamarin.Forms 2.3.4 with a custom FrameRenderer that set Clickable (and LongPressable FWIW) to true, subscribed the respective events and set the FrameRenderers foreground
TypedValue typedValue = new TypedValue();
this.Context.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, typedValue, true);
this.Foreground = this.Resources.GetDrawable(typedValue.ResourceId, this.Context.Theme);
to achieve Material motion (ripple touch).
After updating to XF 2.5 (most likely as of 2.3.5, since fast renderers have been introduced with that release) my touch events have ceased to work. My custom renderer is assigned correctly, so are the Clickable and LongPressable properties, but nothing happens. Partially I have been able to work around the issue - at least for the moment - by subscribing to FrameRenderer.Touch and call OnClick from that event handler. This renders the app usable, but unfortunately lacks the visual feedback in form of the ripple touch effect.
Is there any way I can restore the original behavior? Is there any way to implement a clickable frame with ripple touch in XF 2.5?
With the help of this answer I have figured out a solution. Here's a draft of it:
First of all I store a local reference to my RippleDrawable (see documentation)
private void SetMaterialMotion()
{
TypedValue typedValue = new TypedValue();
this.Context.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, typedValue, true);
this.Foreground = this.Resources.GetDrawable(typedValue.ResourceId, this.Context.Theme);
this._layerDrawable = this.Foreground as RippleDrawable;
}
then I have to subscribe to the Touch event
private void SubscribeClickEvent()
{
if (this.ClickableFrame.IsClickable)
{
this.Touch += ClickableFrameRenderer_Touch;
}
}
In my ClickableFrameRenderer_Touch I set the Pressed property and the hotspot of the RippleDrawable
private void ClickableFrameRenderer_Touch(object sender, TouchEventArgs e)
{
if(e.Event.Action == Android.Views.MotionEventActions.Down)
{
this.Pressed = true;
}
if(e.Event.Action == Android.Views.MotionEventActions.Up)
{
this._layerDrawable.SetHotspot(e.Event.GetX(), e.Event.GetY());
this.Pressed = false;
}
}
This will show the ripple touch motion (more or less) as expected. Of course this does not handle long presses, yet, but I'm on a way.
Anyway, this is not a solution I like very much. I still think that there has to be a supported way on making FastRenderers.FrameRenderer clickable. If anyone knows it: Please share your knowledge.
I am loading a webpage in jxbrowser in java swing, I want to block or disable right click on that page, I searched but not got the answer, please let me know if any one has any suggestion.
Thanks
After a long search, finally I have a working solution for disabling right click
final Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
view.setMouseEventsHandler(new InputEventsHandler<MouseEvent>() {
#Override
public boolean handle(MouseEvent arg0) {
if(arg0.getButton() == MouseEvent.BUTTON3)
return true;
return false;
}
});
The latest JxBrowser has major API changes. If you are using 7.* or above the approach is as follows.
browser.set(MoveMouseWheelCallback.class, params -> Response.suppress());
Available Callbacks
EnterMouseCallback
ExitMouseCallback
MoveMouseCallback
MoveMouseWheelCallback
PressKeyCallback
PressMouseCallback
ReleaseKeyCallback
ReleaseMouseCallback
TypeKeyCallback
Links
What's New
API Documentation
I have an webforms application that I would like to create some automated tests for. This application currently implements Forms Authentication.
What is the best way to accomplish this?
You can use an automated tool such as Selenium or Watin to help drive the test through Internet Explorer or Firefox. At my company, we automate all front end tests using C#, Watin, and Gallio (mbUnit).
You will need to use a tool such as Developer Tools on IE to discover the names/ids of web controls such as textboxes and buttons. Once you have them, you can create Watin objects to represent them. Watin provides basic classes such as Button and TextField.
public class SignInPage
{
public Button SignInButton { get { return Document.Button(Find.ByName(new Regex("login"))); } }
public TextField UserNameEmailTextField { get { return Document.TextField(Find.ByName(new Regex("userNameEmail"))); } }
public TextField PasswordTextField { get { return Document.TextField(Find.ById(new Regex("password"))); } }
............
}
Then you will drive the test through the SignInPage object.
Browser.Page<SignInPage>().UserNameEmailTextField.Value = userName;
Browser.Page<SignInPage>().PasswordTextField.Value = password;
Browser.Page<SignInPage>().SignInButton.Click();
This same procedure is also easily accomplished with Selenium.
Having tried a number of different solutions I keep coming back to this. I need a Window.ShowDialog, using the ViewModelLocator class as a factory via a UnityContainer.
Basically I have a View(and ViewModel) which on a button press on the the view needs to create a dialog (taking a couple of parameters in its constructor) that will process some logic and eventally return a result to the caller (along with the results of all the logic it computed).
Maybe I'm wrong for stilll looking at this from a Windows Forms perspective, but I know exactly what I want to do and I want to ideally do it using WPF and MVVM. I'm trying to make this work for a project, and ultimately don't want to have to go back to vanilla WPF in order to make it work.
I break the rules to implement a dialogwindow but tried to reduce it to a minimum. I have a method OpenDialog in my BaseViewModel:
public void OpenDialog(DialogViewModel model)
{
this.MessengerInstance.Send<DialogViewModel, MainWindow>(model);
}
And in my MainWindow:
Messenger.Default.Register<DialogViewModel>(this, model =>
{
// Instantiate the dialog box
var dlg = new DialogWindow();
// Configure the dialog box
dlg.Owner = this;
dlg.Content = model;
// Open the dialog box modally
dlg.ShowDialog();
});
That way i only have a loose coupling between my viewmodel and my MainView.
You can do the same for closing, my BaseDialogViewModel has a method:
public void CloseDialog()
{
this.MessengerInstance.Send<PopUpAction, DialogWindow>(PopUpAction.Close);
}
(PopupAction is just an enum) and my DialogWindow registers for that:
Messenger.Default.Register<PopUpAction>(this, action =>
{
switch (action)
{
case PopUpAction.Close:
this.Close();
break;
}
});
You could also leave the receiver away when sending, to keep the view class out of the viewmodel but either way i think it's a acceptable solution :)
You can do that. Just create an instance of a page/usercontrol/window and call instance.ShowDialog().
Here's my T4 templates to generate a view/viewmodel with the messaging for closing a window and other tricks.