I am new to using java for XPages development, I want to know if its posible to use JOptionPane Dialog in XPages Project? if yes how? or can i display a dialog component with Java. i tried the below code but notting happened
import javax.swing.*;
public class JOptionPaneMultiInput {
public static void main(String[] args) {
JTextField username = new JTextField();
JTextField password = new JPasswordField();
Object[] message = {
"Username test:", username,
"Password:", password
};
int option = JOptionPane.showConfirmDialog(null, message, "Login", JOptionPane.OK_CANCEL_OPTION);
}
}
I would like to use Java to display a dialog and save retured value in a variable
Swing is not compatible with XPages. XPages is built on JSF and I don't believe any JSF framework supports Swing. Swing is not used for web clients, it is only used for thick clients like Windows or Mac. Xpages is made for presenting to a web browser.
Note: JOptionPane is a part of the Swing framework. You can see this in your import which likely looks like this: javax.swing.*;
UPDATE:
You can definitely accomplish what you are asking. XPages is very feature packed and a great way to develop web applications. It does have a fairly steep learning curve, but thankfully there are already many great free resources out there. I would start with these two:
TLCC has a free introductory to XPages http://www.tlcc.com/admin/tlccsite.nsf/pages/free-xpages-training I also recommend their other paid courses which are very well done.
Notes in 9, (http://www.notesin9.com/) which is a series of free how to videos. Start with the hour long Intro to XPages: http://xpages.tv/xtv3.nsf/allEpisodes.xsp# which is where it all started to click with me.
Related
I'm try show Popup in java program(web).
I try ScriptEngine with javascript, nashorn but fail. Because alert,confirm, prompt is not method of js.
Code in java program:
ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
engine.eval(new FileReader("script.js"));
Invocable invocable = (Invocable) engine;
invocable.invokeFunction("openPopup", "ABC XYZ");
and in script.js:
function openPopup(str){
alert(str);
}
Run it, error show:
"alert" is undefined
Explanation
Opening a JavaScript popup in Java is not possible. The JavaScript Engine Nashorn does not provide this method. It usually is a functionality provided by browsers.
That is also why you are getting:
"alert" is undefined
Solution
You can open popup windows with different tools in Java, for example Swing or JavaFX. Those are tools with which you can create programs with graphical user interfaces (GUI), i.e. that have windows.
Here is an official tutorial by Oracle on how to create dialogs with Swing.
The relevant method for creating just a simple popup is:
JOptionPane.showMessageDialog(frame, "Hello world!");
Where frame is a reference to the window which should be the parent of this popup. However you can simply pass null for a quick and dirty popup:
JOptionPane.showMessageDialog(null, "Hello world!");
Just use the above code, import the JOptionPane and it should work:
import javax.swing.JOptionPane;
The class has more interesting methods to check out, like input dialogs. Here is its documentation.
The JavaFX solution is a bit more complicated as it requires you to setup the frame and handle several events.
You may check out this other question SO: Popup window with table view in JavaFX 2.0. It uses the designated class Popup (documentation).
I have integrated the GWT application with Chrome packaged app with help of DirectLinkerinstaller like the code below:
public class CSPCompatibleLinker extends DirectInstallLinker {
#Override
protected String getJsInstallLocation(LinkerContext context) {
return "com/google/gwt/core/ext/linker/impl/installLocationMainWindow.js";
}
}
But now I want to call print function from Chrome packaged app. When I call window.print() it allows me to print current window, but I need to open a new separate window and print that.
Could you anyone please help me in this?
I can't answer anything about GWT or DirectLinkerinstaller, but here's an answer about Chrome Apps, assuming that's what you're asking about:
You use the chrome.app.window.create API to create a window. Then, you can call the print method for that window.
In my apps, I seldom want to print what's in a window, but rather something I've generated specifically for printing. For that, I create a PDF with jsPDF (Google it), which works well. Then I display the PDF in a window, and let the user print the PDF (or save it).
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 .
I just started creating a SWT/JFace application using the (now free) WindowBuilder from Google (previously instantiations).
I find the Data binding part difficult although it -should- make it easier for me.
For instance, I cannot bind the enabling-property of a button to a (myself defined) boolean function.
Are there any resources (demos, text, tutorials, examples) about using the WindowBuilder GUI and/or the data binding principle?
The information found on the google page or the instantiations page did not help me enough.
For what it's worth:
bindingContext.bindValue(
new ComputedValue() {
public Object calculate() {
// calculate the enablement using the value of other, previously
// created observables.
}
},
WidgetProperties.enabled().observe(theButton)
);
The Eclipse newsgroups are a great place to ask these questions. Try the eclipse.platform.jface newsgroup.
Hi all this is my first Question here!
Im just making my first steps with (Ext-) GWT. I´m testing the Ext-GWT libraries and really: These are absolute great!
Now my question:
Is it possible to make a kind of "clear-Portal" or "hide all portles" for a defined Portal?
Or have i always manually clear the portal like in my example code above?
My sample code looks like this:
//define the Portal, 2 columns, each 50% auf width, with borders and Backgroundcolor
portal = new Portal(2);
portal.setBorders(true);
portal.setStyleAttribute("backgroundColor", "white");
portal.setColumnWidth(0, .50);
portal.setColumnWidth(1, .50);
//define a Portlet for showing all Users
portletUser = new Portlet();
portletUser.setHeading("Benutzer");
configPanel(portletUser);
portletUser.setLayout(new FitLayout());
CompUserList compUserList = new CompUserList();
portletUser.add(compUserList);
portletUser.setHeight(250);
//define a Portlet for showing all Vehicles
portletVehicles = new Portlet();
portletVehicles.setHeading("Fahrzeuge");
configPanel(portletVehicles);
portletVehicles.setLayout(new FitLayout());
CompVehicleList compVehicleList = new CompVehicleList();
portletVehicles.add(compVehicleList);
portletVehicles.setHeight(250);
//define a portlet for showing all countries
portletCountries = new Portlet();
portletCountries.setHeading("Länder");
configPanel(portletCountries);
portletCountries.setLayout(new FitLayout());
CompCountryList compCountryList = new CompCountryList();
portletCountries.add(compCountryList);
portletCountries.setHeight(250);
//add both Portlets to Portal
portal.add(portletUser, 0);
portal.add(portletVehicles, 1);
So first of all this works fine and looks great :-)
Now i have a a button in a accordeon menu. The Listener on this button should hide all portlets in the portal (at this time its the portletUser and portletVehicles) and then add another portlet (for example the portletCountries):
portletUser.hide();
portletVehicles.hide();
portal.add(portletCountries, 0)
Question from above again ;-)
Is it possible to make a kind of "clear-Portal" or "hide all portles" for a defined Portal?
Or have i always manually clear the portal like in my example code above?
What is the best practice for this functionallity?
Thanks all for your tips!
Lars.
I haven't used Ext-GWT -- but looking at the Javadoc for Portal there are two things I would try:
for (LayoutContainer c : portal.getItems()) {
c.hide();
}
or, more generally, wrap a Portal in your own class which records the Portlets which are in the Portal -- then you can get a List rather than List.