Using JTextPane to display HTML, is SVG supported? - java

I'm trying to embed svg images in the HTML, they don't appear to be working with the or tag. Does anyone know how to do this?

Swing support only a subset of HTML/CSS/JavaScript.
JavaFX has better support as shown here.

like this:
</head>
<body>
<object width="700" height="200" data="fileName.svg"></object>
</body>
</html>

Related

Display XML in html with CSS style sheet

I have seen numerous ways to display an XML file in a web page (HTML) but haven't come across one that uses a CSS style sheet.
I have an XML file that already has a CSS style sheet. When the .xml is viewed in a web browser, it displays fine with CSS.
I want to display the same XML file in a webpage (HTML), whats the best way to do that?
Thanks.
If you have a separate styled XML document and you want to display it in an HTML page, you could probably use the <object> tag:
<object height="100%" width="100%" border="0" type="text/xml" data="yourfile.xml">
<!-- alternative content used when the inclusion fails -->
</object>
(Tested in FireFox only). Alternatively, an <iframe> could do a similar job.

No Sign of Applet Running from HTML

I put together a java ChatClient and ChatServer on Max OS X Version 10.7.5 for fun with my kids. We were using Java Version Java(TM) SE Runtime Environment (build 1.7.0_04-b21). It runs great from the Terminal. Also, we'd like to able to run it from Eclipse by passing in parameters.
When I open the HTML in Safari 6.0.2., I get no sign of errors or the applet running. In Safari, I have enable plug-ins, Java, and Javascript. Only the text in the HTML is displayed; the applet does not seem to run or anything.
Once I get this working, I would like to package in a JAR file and sign it so I can create a socket to my server. The applet is a simple guy that asks to connect via socket, then sends and receives text from any other clients including itself.
<Html>
<Head>
<Title>Java Example</Title>
</Head>
<Body>
This is my page<br>
Below you see an applet<br>
<br>
<Applet Code="ChatClient" width=200 Height=100>
<PARAM name="host" value="xxxxx-iMac.local">
<PARAM name="port" value="4445">
</Applet>
after Applet
</Body>
</Html>
In section 13.4, the APPLET tag in HTML is deprecated, and it's successor is the <object> element. You should think about a couple things here -
First, abide by HTML standards. This includes having all of your html tags and attributes in lowercase. <PascalCase>, <camelCase> are not standard for HTML.
Second, switch your applet tag to an object.
Thirdly, wrap all text in a block tag other than <body>. Most popular one is <p> meaning paragraph.
Fourthly, wrap ALL html attribute values in double quotes. example: width=200 should be width="200"
Fifthly, think about doing 2 spaced tabs when doing html. it's much cleaner :)
I could go on, but i could be here forever. Bottom line is, follow standards.
But to answer your question:
In the specification, it looks like it expects the file name. this includes ".class" at the end. Try,
<html>
<head>
<title>Java Applet Example</title>
</head>
<body>
<div id="container">
<applet code="ChatClient.class" width="200" height="100">
<param name="host" value="xxxxx-iMac.local" />
<param name="port" value="4445" />
</applet>
</div>
</body>
</html>

Trouble embedding Java applet into an html page

I currently have a relatively simple Java applet which I am trying to embed into an html page. I've looked around, and haven't found a suitable answer. Many answers refer to using the deprecated <applet> tag, and the rest do not seem to work for me.
This is the body of my page. I initially tried using the <applet> tag and it worked, however I was unable to get it to use the full height of the page, and then I found it is deprecated anyways.
I've tried this on Firefox, Chrome, and IE, and it won't work on any of them. It only shows the alternative text.
I did read that the <object> tag only works for IE, but even so it isn't working for me. Likewise, most of the information I found is outdated.
<body>
<object width="500" height="500" data="project">Your browser does not support the <code>object</code> tag.
</object>
</body>
Ive had no problems using the applet tag to get applets to display to a desired width and height. All the Java resources point to using the same tags. I'm no html guru though, so I'm not sure if there's another solution.
<applet code= "myJavaApplet.class" width="600" height="700">textgoeshere</applet>

Display an applet in a webpage using HTML/JavaScript

I have very little experience with HTML and applets. I have tried several of the things I found online, but am unable to make my Java applet run in a web browser (it functions in eclipse).
I have put the HTML file in the same folder as all of my Java class files for the applet. I am currently using Safari, but would like the applet to work in most any popular browser.
How can I display a java applet on a webpage using HTML/JavaScript? Can anyone offer any tips/advice?
Below is my attempted HTML code.
Attempt 1:
<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<embed code="PendulumApplet.class"
width="200" height="200"
type="application/x-java-applet;version=1.5.0"
pluginspage="http://java.sun.com/j2se/1.5.0/download.html"/></embed>
</Body>
</Html>
Attempt 2:
<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="200" height="200">
<PARAM name="code" value="Applet1.class">
</OBJECT>
</Body>
</Html>
Try below code
<APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
</APPLET>
OR
<object width="400" height="400" data="helloworld.class"></object>
Good Luck...
Use deployJava.js to write the applet element. The script is supported by Oracle, and will:
Check the user has the minimum required Java, prompting them to install if not, before..
Writing the object/embed or applet element as is best known for that browser.
Other notes:
Is it PendulumApplet.class or Applet1.class? It is hard enough to debug problems on international forums without introducing doubt about the name of the applet class.
The .class extension in the code attribute is tolerated, but not correct. The value should be a string representing the Fully Qualified Name of the class. E.G. javax.swing.JApplet as opposed to javax.swing.JApplet.class.
HTML element names should be all lower case (e.g. <html> as opposed to <Html>)
What output do you see in the Java console? When debugging applets in a browser, it is vital ensure the Java Control Panel is configured to pop open the console on discovering an applet (or JWS app.).
Although I have not done so myself, my Java textbook provides this outline for an embed:
<applet
code = "ClassName.class"
width = 250
height = 50
[archive = archivefile]
[vspace = vertical_margin]
[hspace = horz_margin]
[algin = applet_alignment]
[alt = alt_text]
>
</applet>
(Optional parameters in brackets)
I was having this SAME issue myself.
Using <applet code=""></applet> doesn't work, but <Applet> or <APPLET> seems to work.
Google Chrome and IE.

Two Applets in same page

I am trying to put two applets which share same code base but initialized with different paramaters in same web page.
process goes like this:
applet.jar->create two applet tags, with different parameters, same jar in a page->deploy to server->access the page.
HTML looks like this:
<HTML>
<HEAD>
<TITLE>Java applet example - Passing applet parameters to Java applets</TITLE>
</HEAD>
<BODY>
<APPLET CODE="Applet.class" WIDTH="400" HEIGHT="50">
<PARAM NAME="PURPOSE" VALUE="VIEW">
</APPLET>
<APPLET CODE="Applet.class" WIDTH="400" HEIGHT="50">
<PARAM NAME="PURPOSE" VALUE="MODIFY">
</APPLET>
</BODY>
</HTML>
there is a panel in both applets which display messages...
Now, the problem is messages from one applet are displaying in other one!
This kind of behaviour (and worse) is often caused by mutable statics (sometimes dressed up as singletons). For many reasons, don't use mutable statics.
I think that if you add MAYSCRIPT to the APPLET tag, this will make your applet isolated with the other.
<APPLET CODE="Applet.class" WIDTH="400" HEIGHT="50" MAYSCRIPT>
<PARAM NAME="PURPOSE" VALUE="MODIFY">
</APPLET>
Ok, it's not clean but if you can't change the codebase that's an easy way to fix this thing.

Categories