I created a winform form with a button and when I click on the button I´m invoking a Java AWT (.jar) process. After that I embed this process into a Panel using SetParent(...). The code:
var procStartInfo = new ProcessStartInfo();
procStartInfo.WindowStyle = ProcessWindowStyle.Normal;
procStartInfo.FileName = "file.jar";
var process = Process.Start(procStartInfo);
var container = new FormContainer();
container.Show();
Panel p = new Panel();
container.Controls.Add(p);
SetParent(process.MainWindowHandle, p.Handle);
The problem is when I embed the jar... the textboxes are not responding to any keypress event. I supose that the issue is related to the Java Swing application. Using any other moderm Java application every thing is working fine
Any idea if I need anything else to solve that problem
The problem is the bridge focus handler. In the java 1.8 version, the focus handler use multithread code and it seem that is it the problem in the java embeded application. We remove the async code and it works fine
Related
I'm working on a Netbeans Platform application running on Java 11 in which I'd like to use the chromium browser from the JCEF project. (org.jcef)
I've already implemented the browser within an org.openide.windows.TopComponent and that works just fine by implementing it in the constructor like so:
public BrowserTopComponent() {
initComponents();
CefSettings settings = new CefSettings();
settings.windowless_rendering_enabled = false;
File jcef_helper = InstalledFileLocator.getDefault().locate(
"modules/lib/jcef_helper.exe",
"com.mycompany.nbm.browser",
false);
settings.browser_subprocess_path = jcef_helper.getAbsolutePath();
modules_path = jcef_helper.getAbsolutePath().split("modules")[0] + "modules";
cefApp_ = CefApp.getInstance(settings);
client_ = cefApp_.createClient();
browser_ = client_.createBrowser(HOME, false, false);
browerUI_ = browser_.getUIComponent();
add(browerUI_, BorderLayout.CENTER);
}
Now I'd like to include the browser in another TopComponent but not in its entire area, but instead within just one jPanel.
Theoretically that should be possible by exchanging add(browerUI_, BorderLayout.CENTER); from the previous code with:
jPanelBrowser.add(browerUI_, BorderLayout.CENTER);
jPanelBrowser.validate();
That however did not work at all. It doesn't throw any errors, it just doesn't do anything.
If anyone has any experience in making jcef work in such a scenario, any help would be greatly appreciated!
I ran into a similar issue and found that when you are adding it to a JPanel you have to set the size of the client.
client_.setSize(800, 600)
Once I did that it showed for me.
I'm creating an SWT (ported Mac OSX version) application. I am trying to set a specific button to have the bezel style of "inline". Here is what I want my button to look like on mac.
(screenshotted in storyboard view in xcode)
The code I am using to try to get this inline button:
// created button named "inlineButton" and applied layout to it.
// here is where I set the bezel style and text.
NSButton nsInlineButton = (NSButton) inlineButton.view;
nsSaveButton.setBezelStyle(15); // NSBezelStyleInline is enum 15 for cocoa
this.inlineButton.setText("Inline Button");
And the result:
(screenshotted from my java program)
I have also tried to redraw and relayout the shell and a variety of other methods with no avail.
Is this a bug or am I doing something wrong?
Solved. I just needed to add the SWT style of "FLAT"
this.inlineButton = new Button(this, SWT.FLAT);
NSButton inlineButton = (NSButton) inlineButton.view;
inlineButton.setBezelStyle(15);
Is there any way to open a new window with a specified URL using java only.I know that we can use window.open in javascript but i need it to be in java page.Anyidea?.
You can use Applet's context and the showDocument() method.
Example:
String link = "http://www.google.com";
URL u = new URL(link);
AppletContext a = getAppletContext();
a.showDocument(u,"_self");
You can change the window/tab opening the link by changing the _self to _blank
If it's indeed an applet, and you want to create a Java window (JFrame or similar), see AlphaMale's comment.
If what you want instead is a new browser window, you can either follow inquizitive's answer, or alternatively use JSObject to run arbitrary JavaScript code:
import netscape.javascript.*; // add plugin.jar to classpath during compilation
...
JSObject window = JSObject.getWindow(this);
window.eval('window.open(url)');
This is more useful to interact with the page's scripts, of course, if what you want is just open another tab using the Applet API may be simpler.
I am using GXT for UI development. I have used HTML5 for Dragging file from Desktop to my application and upload it. But now i am having reverse requirement. I want to drag files from browser to desktop which will download the file to desktop.
I know that is possible in Chrome only. And had checked the below demo:
http://www.thecssninja.com/javascript/gmail-dragout
I had tried to implement the above code in my GXT application, but the issue is that i am using Editable Grid which is supporting DnD to TreePanel. Now when i drag from grid to Desktop i think its not capturing the browser event (may be i am wrong here).
Any idea, how it should be done?
Thanks.
Below is the small piece of code which i call after the Data had been inserted in Grid. All records are having the CSS class name as ".icon". The problem is that when i start to drag, the "dragstart" is not being called. Any suggestion?
NOTE: This code is working when i create Buttons, Labels, etc and making them draggable=true with other required parameters.
public static native void test(String id)/*-{
var files = $doc.querySelectorAll('.icon');
for (var i = 0, file; file = files[i]; ++i) {
file.addEventListener("dragstart",function(evt){
$wnd.alert("Drag Event started.. ");
evt.dataTransfer.setData("DownloadURL",this.dataset.downloadurl);
},false);
}
}-*/;
I used this, and it successully performs, no you should check some other place in your code.
I want to design new Git client with a clean GUI.
Is it possible to use the power of HTML, CSS and JavaScript in a java application?
I would like to use Java + JGit for models, Java for controllers and HTML + CSS + JavaScript for views.
I don't want a client-server model. I would like to integrate Java and HTML nicely. A DOM event would fire events directly to a Java controller. This way it would be possible to create rich offline application.
You can embed web browser component into your Java Swing/JavaFX Desktop application that displays GUI built with HTML5+CSS+JavaScript. You can see an article that describes how to do this at https://jxbrowser-support.teamdev.com/docs/tutorials/cross-desktop-apps.html
One of the Java Swing/JavaFX libraries that allows embedding Chromium into Java applications is JxBrowser. Using JxBrowser API you can load any web page and work with its DOM and JavaScript. You can even call Java methods from JavaScript code and vice versa. For example:
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.JSFunctionCallback;
import com.teamdev.jxbrowser.chromium.JSObject;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
public class JavaScriptJavaSample {
public static void main(String[] args) {
Browser browser = new Browser();
browser.addLoadListener(new LoadAdapter() {
#Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()) {
Browser browser = event.getBrowser();
JSObject window = (JSObject)
browser.executeJavaScriptAndReturnValue("window");
window.setProperty("MyFunction", new JSFunctionCallback() {
#Override
public Object invoke(Object... args) {
for (Object arg : args) {
System.out.println("arg = " + arg);
}
return "Hello!";
}
});
JSValue returnValue = browser.executeJavaScriptAndReturnValue(
"MyFunction('Hello JxBrowser!', 1, 2, 3, true);");
System.out.println("return value = " + returnValue);
}
}
});
browser.loadURL("about:blank");
}
}
It's not really feasible. Rich clients in Java are done using Swing or SWT.
If you want to use HTML/CSS for your user interface, you need to use the server/client model. It can be as simple as creating a local server and launching a browser that connects to it, but it would still be that model.
If you absolutely need to have HTML/CSS as your UI framework and can't go to a server/client model, your best bet is probably looking at something like Google Native Client, but that uses C/C++ bindings on the backend. I haven't used Native Client so I can't personally give much more information on that front.
Edit to add:
One option is to embed a native browser into your Swing app using something like: http://djproject.sourceforge.net/ns/
There are some pure Java HTML renderers, however, they most likely won't be fully HTML5/CSS3 compliant, let alone possibly have Javascript bugs as well.
See here for some of those options: Pure Java HTML viewer/renderer for use in a Scrollable pane
Like #Reverand Gonzo says, you will need some form of server/client. But you could easily embed a Jetty server into a Java app and then use GWT for your client code.
You can bring in the power of HTML,CSS,JavaScript into your Swing app using JFXPanel to embed JavaFX WebView. Have a look at the SimpleSwingBrowser demo in this link:https://docs.oracle.com/javase/8/javafx/interoperability-tutorial/swing-fx-interoperability.htm
WebView allows to call JavaScript functions from Java and vice versa. It is also a nice way to enhance your legacy Java app with web technologies.
JavaFX 2.2 brought this functionality to providing a user interface component (GUI) that has web view and full browsing functionality.
For more details, see Adding HTML Content to JavaFX Applications.
Use Angular.js with HTML and rest of the things as same in Java, just use classes for business logic, no need to write code for awt/swing. Angular with spring boot are rapid development in Java for webapp with less code in Java without swing use to create best webapp .