I am writing a Java program that creates HTML code.
What's the best/easiest possibility to have a preview of the code?
Show the code in the JFrame: How can I do this?
Open the windows browser with the created File? Is this possible?
A totally different approach?
Both are quite easy to do. Here is a page from the Java tutorial that shows how to display HTML in Swing (you'd use a file: URL to display the contents of a file.) You can display a URL in an external browser using Java 6's Desktop class:
Desktop.getDesktop().browse(new URI("file://myfile.html"));
Alternately, save the data in a file with the *.html extension and use
Desktop.getDesktop().open(new File("myfile.html"));
Related
I have a problem, I want to embed a Jar into my html code.
The problem is that I use JFrames and not in my java Code. If i use Applets what was an example for a solution my Programm doesnt work anymore because of diffrent error messages,their is no Problem with set Title, so I wanted to ask if their is any way to embed my Jar file into my website without making it to an Applet.
I need to render HTML page from a Java String. The String contains a full HTML page which may include CSS and Javascript. I know that some CSS/script reference may missing because I only has the html, so it's not a problem.
I have tried using JEditorPane, but it only works for very simple HTML. If it can't render, it will display nothing.
Is there any library I can use?
You can use the Desktop class. It will open the default browser of your platform.
Read the section from the Swing tutorial on How to Integrate With the Desktop Class for more information and working examples.
I need to test Java Applet written in AWT for browsers, but I don't know how to connect to existing frame/dialog/button.
Is any option to get list of existing AWT object in system, and do something with them?
I tried with FEST-AWT, but if I understand correctly, he only allow to create new objects and do things on them.
I have only written one applet in the browser with AWT. What i did was whipped up a basic XHTML document and used the "applet" tag. You put this in the same directory as your .java applet, passing it the arguement code="InitClass.class" (double check that is the right name for the arguement). From there, you compile your applet in your IDE and then open your html doc in your browser. applet tag was deprrcated in HTML4
As school project I need to develop a java Mid let that will ask for a URI. Then the
application will make an HTTP connection using the given URI and retrieve a HTML
page, and display it to the user.
I am able to give the HTML link but it displays the HTML code when I run the application.
i am using java net beans
Thanks, any help is really appreciated
What you actually need is to open native browser and show HTML page in it. This can be done using platform call:
getInstance().platformRequest("http://bombusqd.hdd1.ru/m/")
getInstance() is a method of MidLet.
Here is a little snippet of what I need to do:
if (Desktop.isDesktopSupported())
{
final Desktop desktop = Desktop.getDesktop();
try{
desktop.open(new File(path));
}
catch (final IOException e)
{
MessageBox.alert("Log View", "Error finding file", null);
}
}
I need to open a file in the logged in users default desktop application for that file type. Maven is giving me issues on build saying it can't find java.io.File and java.awt.Desktop.
Kind of a 2 part question, first, does GWT have some sort of similar functionality to java.awt.Desktop and how do I fix the project so maven finds the io and awt files?
To get the same effect as a JButton calling Desktop in HTML, you would provide an HTML button that links to a download of the file and ensure it has the correct content-type provided by the server.
Specifically to the GWT part of the question.
Yes you can do this. You would likely use either use a Grid, FlexTable, HTMLTable or event just HTML to display. You would embed that widget into a panel, and display that panel on the root panel.
The trick will be to get the file data from the server to the client. You can do that using either GWT RPC, or some kind of REST server. If you look at the default app that is produced when you start a GWT application, it will send back string data based on a string. You can use that as a pattern to bring down your model object. The default app uses GWT-RPC, and is pretty easy to follow.
The reason why I was vague on the type of widget is it will depend on how you want to present this data to your user. You can use an HTML to just render HTML, but I would think you would want to use a better widget to truly render this data.
No, you can't do this with GWT.
Browsers typically have no access to the file system. The best you can do is have the users install some plugin that gives you file access (will require a permission check) or have them upload a file to your server (your web app can download the file from there to inspect it).