JxBrowser does not launch from another class - jxbrowser

I have a problem that I cannot launch my JxBrowser from another class but it works fine on its own class. I will give the code for the internet browser class here
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import javax.swing.*;
import java.awt.*;
public class InternetBrowser
{
//properties
Browser browser;
BrowserView browserView;
JFrame frame;
//constructor
public InternetBrowser()
{
browser = new Browser();
browserView = new BrowserView(browser);
frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.loadURL("https://www.youtube.com/embed/bO7yYDIOuXo");
}
public static void main( String [] args )
{
InternetBrowser browser = new InternetBrowser();
}
}
The error that I get is
Class StartIPCTask is implemented in both /private/var/folders/cs/1z68c1xs2q3crwrwm__fx_t80000gn/T/jxmaps-chromium-49.0.2623.110.unknown/data/Temp/libjxmaps-common64-397f2f15-9ac5-4806-91f6-88c8aaa29714.dylib (0x1288d5630) and /private/var/folders/cs/1z68c1xs2q3crwrwm__fx_t80000gn/T/browsercore-64.0.3282.24.6.21/data/Temp/libbrowsercore-common64-01e73e7f-2b85-4bd3-ac76-05d908fa4928.dylib (0x16b2576c8). One of the two will be used. Which one is undefined.
I need to define which one of the directories that the class should use but I do not know how. I am using the latest version of Netbeans. Also at the top of the class that im trying to construct a browser, the imports are highlighted as "unused import". Thank you for your help!

I realized that this is a bug seen in OSX.. The program works without any problem in windows computers.

In general, this warning doesn't affect the program, so you can just ignore it. If you don't want to receive it at all, then please try using the jxbrowser.jni.singleton.fix=false VM parameter.

Related

How to Access JavaFX Virtual Keyboard (FXVK) Using Open JDK 15 or beyond?

I use the javafx virtual keyboard with open jdk 8. At times I have to access the virtual keyboard to prevent it from displaying when certain text fields get focus. An example of this is a screen where an operator has to scan in multiple barcodes. This virtual keyboard gets in the way. With open jdk 8 we were able to disable the virtual keyboard like this:
FXVK.detach(); //after importing "com.sun.javafx.scene.control.skin.FXVK"
We are now upgrading to open jdk 15 and building our UI with gradle. "com.sun.javafx.scene.control.skin.FXVK" is no longer accessible with a modular project with gradle. I don't believe using a different virtual keyboard is an option so can anyone explain how to access this FXVK class after java 8?
Is there a way to use --add-exports or --patch-module with a JAR to patch JavaFX to gain access to the internal class?
Below is the code for a sample project that shows this problem.
This is the JavaFX Application class that simply displays a text field and shows the code I could use with java 8 to not show the virtual keyboard.
package com.test.sampleapp.application;
////not accessible in java 15
//import com.sun.javafx.scene.control.skin.FXVK;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application{
public static void main(String[] args)
{
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception
{
Label label = new Label("Text field below");
TextField textField = new TextField();
VBox vbox = new VBox(label);
vbox.getChildren().add(textField);
Scene scene = new Scene(vbox);
primaryStage.setScene(scene);
primaryStage.show();
textField.focusedProperty().addListener(new ChangeListener<Boolean>()
{
#Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue,
Boolean newValue)
{
// If focused
if (newValue)
{
//Need this to disable the virtual keyboard when using a textfield with scanning
//FXVK.detach();
}
}
});
}
}
Then I needed to add a wrapper class to have the virtual keyboard show up. Please note that most of the time I do use the virtual keyboard when text fields get focus, it's other times where I need to be able to programmatically disable it during certain situations.
The wrapper class:
package com.test.sampleapp.application;
import java.lang.reflect.Method;
public class AppWrapper
{
public static void main(String[] args) throws Exception
{
Class<?> app = Class.forName("com.test.sampleapp.application.Main");
Method main = app.getDeclaredMethod("main", String[].class);
System.setProperty("com.sun.javafx.isEmbedded", "true");
System.setProperty("com.sun.javafx.touch", "true");
System.setProperty("com.sun.javafx.virtualKeyboard", "javafx");
Object[] arguments = new Object[]{args};
main.invoke(null, arguments);
}
}
Let me know if you need anything else such as the build.gradle file however this is mostly just an issue using java 9 or beyond.
The FXVK class still exists in the same package, so the only issue is that its package is not exported by the javafx.controls module. If you must use this internal class, then you can pass an appropriate --add-exports JVM argument both at compile-time and at run-time.
Here's a simple application that calls FXVK#detach():
// Will fail at compile-time if the '--add-exports` argument is not
// passed to 'javac'
import com.sun.javafx.scene.control.skin.FXVK;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
var root = new StackPane(new Label("Hello, World!"));
primaryStage.setScene(new Scene(root, 600, 400));
primaryStage.show();
// Will fail at run-time if the '--add-exports' argument is
// not passed to 'java'
FXVK.detach();
}
}
Assuming you put the Main.java file in your working directory, you can compile it with:
javac -p <path-to-fx> --add-modules javafx.controls --add-exports javafx.controls/com.sun.javafx.scene.control.skin=ALL-UNNAMED Main.java
And run it with:
java -p <path-to-fx> --add-modules javafx.controls --add-exports javafx.controls/com.sun.javafx.scne.control.skin=ALL-UNNAMED Main
If your code is modular then you can get rid of the --add-modules and you must change ALL-UNNAMED to the name of your module. Plus, make sure to launch your application via --module (or -m). Note the -p above is shorthand for --module-path.
If you use a build tool (e.g., Maven, Gradle, etc.), then you'll have to lookup how to set these JVM arguments for that tool. You'll also have to take into account how you deploy your application. For instance, if you use jpackage then you can use its --java-options argument to set the --add-exports option for when your application is launched.
You may also need to tell your IDE that you are giving yourself access to the internal package. Otherwise, your IDE will likely yell at you for trying to use an inaccessible type.

Getting a popup for downloading the font file(ttf) in a spring-boot application

I'm getting a popup for downloading the fonts files(ttf) in a spring-boot application, the font file is related to bootstrap3.
I tried to add MimeTypes like this but still getting the popup for first time I open the application.
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.context.embedded.MimeMappings;
import org.springframework.stereotype.Component;
#Component
public class ServletCustomizer implements EmbeddedServletContainerCustomizer {
#Override
public void customize(ConfigurableEmbeddedServletContainer container) {
MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
mappings.add("woff","application/x-font-woff");
mappings.add("eot","application/vnd.ms-fontobject");
mappings.add("ttf","application/x-font-ttf");
container.setMimeMappings(mappings);
}
}
I'm using Spring-boot 1.3.3.RELEASE+thymeleaf.
Anyone know how to resolve this issue?
I resolved the issue by adding this line to my security config
http.authorizeRequests().antMatchers("/fonts/**").permitAll();

my code is not running in webdriver

I am running a simple code to open google.co.uk in a firefox broswer but after the running the code in eclipse, it only opens up the browser stops there. Please help. Here's the code-
package basic_webdriver;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Driver_Test {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("https://www.google.co.uk/");
System.out.println(driver.getTitle());
}
}
Try
driver.Navigate().GoToUrl("https://www.google.co.uk/");
The Navigate function tells the browser to navigate somewhere.
The GoToURL function indicates that the browser should navigate to a specific URL.
The string for the URL is input as a parameter for the GoToURL.
The above should make the browser navigate to a specific URL.

Saving Screenshot file

My code for saving screenshot file is:
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\screenshots\\"+Filename+".jpg"));
The Error is :
The method copyFile (File, File)is undefined for the type FileUtil
I use an EventFiringWebDriver . Any ideas on this.
There are two possible explanations.
The error message you provided mentions FileUtil class instead of FileUtils You may have used wrong class by mistake.
Assuming you are using the correct FileUtils class you may have imported wrong package. Make sure that you have imported org.apache.commons.io.FileUtils
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
I guess you missed one or more of these imports.. The code given above works fine for me with these includes.
Plz put the exception then it will work fine.
EG: public static void main(String[] args) throws IOException
public class Testscreenshot {
public static void main(String[] args) throws IOException {
System.out.println("Images saved ..");
WebDriver driver = new FirefoxDriver();
driver.get("https://google");
File scrFile;
scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
org.apache.commons.io.FileUtils.copyFile(scrFile, new File("C:\\Users\\R&D\\Desktop\\Tulas\\Javafiles\\testimages.png"));
driver.quit();
}
}
Use import org.apache.commons.io.FileUtils.
This imports the FileUtils class you need.

How to use fonts in external SWF files

What I would like to do is a flex app, that uses fonts that are available in external swf.
What I have succeded so far is:
to create a AS class hat holds the embedded font:
package
{
import flash.display.Sprite;
public class _Arial extends Sprite
{
[Embed(source='C:/WINDOWS/Fonts/ARIAL.TTF', fontName='_Arial', unicodeRange='U+0020-U+002F,U+0030-U+0039,U+003A-U+0040,U+0041-U+005A,U+005B-U+0060,U+0061-U+007A,U+007B-U+007E')]
public static var _MyArial:Class;
}
}
compiled this into a swf with following command: mxmlc.exe -static-link-runtime-shared-libraries=true _Arial.as
When I try to load the font from my flex app, this fails with following error message:
ArgumentError: Error #1508: The value specified for argument font is invalid.
at flash.text::Font$/registerFont()
at valueObjects::FontLoader/fontLoaded()[C:\Documents and Settings\nutrina\Adobe Flash Builder 4\flex_pdf\src\valueObjects\FontLoader.as:33]
This is the code where I try to load the SWF file:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.*;
import mx.collections.ArrayCollection;
import mx.core.FontAsset;
public class FontLoader extends Sprite {
public function FontLoader(url:String) {
super();
loadFont(url);
}
private function loadFont(url:String):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fontLoaded);
loader.load(new URLRequest(url));
}
private function fontLoaded(event:Event):void {
var fontList:ArrayCollection = new ArrayCollection(Font.enumerateFonts(true));
var FontLibrary:Class = event.target.applicationDomain.getDefinition("_Arial") as Class;
trace("FontList: " + fontList)
trace("FontLibrary: " + FontLibrary)
trace("FontLibrary._Arial: " + FontLibrary._MyArial)
Font.registerFont(FontLibrary._MyArial);
fontList = new ArrayCollection(Font.enumerateFonts(true));
trace("Font list: " + fontList)
}
}
}
The font file is definitely not corrupt because if I put the _Arial class from the code above into the Flex application, the embedding works. So my guess is that probably I missed some compilation options?
I am using Adobe Flash Builder 4.
I would appreciate any help on this matter.
Thanks,
Gerald
Could be a problem with class name conflicts. I wrestled with an external font loading issue for hours. Turns out my font class was called "Main", and so was the application that was trying to load it. The font never got registered correctly.

Resources