How to render basic HTML markup inside a JPanel in Java Swing? - html

I want to do something really simple like this:
JPanel htmlPanel = new HtmlPanel("<html><body><h1>hello world</h1></body></html>");
I think I had seen code somewhere that did exactly this. What about CSS and JS? Can the JPanel be made to support this easily? Are there libraries somewhere that do what I am asking for?

Check here to see how to add CSS support to your JEditorPane. You will need an HTMLEditorKit.
I do not see why you would need JavaScript support for a JEditorPane. The basic use of it is to render Help pages written in HTML and CSS.
If you need to have the real McCoy embedded into your application, try the Lobo Java Web Browser. Lobo does JavaScript and CSS and is open source 100% Java.
November 2015: The latest fork of the Lobo Browser is Lobo Evolution.

Sounds like you were thinking of the JEditorPane. It can display html from e.g. an URL.
Swing tutorial, Editor panes.
The support for javascript is nonexistent.
You can try out third party components such as flying-saucer, which is a XML/XHTML and CSS 2.1 renderer in pure Java.

In case anyone is still looking for an easy solution to just enable display of HTML-Markup: Use a JLabel and enclose the text in '<html>' and '</html>' (body tag isn't needed).
Have a look at How to Use HTML in Swing Components. I just came across this when looking for an easy way to display data in tables, and it works like a charm.

There was JWebPane, a Java component based on WebKit, but that project seems to have died a long time ago and/or has just gone quiet. Some people are still hoping it will be released, The other one I know of is WebKit for SWT, but it appears to be for Win32 only. :(

Related

Suitable C++ widget for showing static html page

I need to create simple cross platform C++ project for rendering (displaying) html pages (let it be application that displays help materials). This pages can include some images and styles (css inserted in html). So I search for the best approach to have the next functionality in my project:
Possibility to show and zoom formatted html text;
Possibility to show and zoom images as well as text;
CSS support;
Easy to deploy - widget used in app should be lightweight and shouldn't have a lot of extra dependencies.
I tried to use QTextEdit. But unfortunately as the Qt documentation says, QTextEdit zoom methods do not change the size of any images.
Also tried to use QWebView there (Qt5.4). But after switching to Qt5.6 I noticed that Qt WebKit is deprecated and not supported any more. On other hand replacing Qt WebKit functionality with one from the Qt WebEngine is painful. Furthermore Qt WebEngine module is huge and has a lot of dependencies from parts that I actually not used (e. g. it depends a lot from chromium web engine). So I don't need full web browser in my application.
So what is the best approach (may be some lightweight widget that is free to use) to implement functionality mentioned above?
Thanks in advance.
I have no experience with this library, but I've heard lots of good things about it:
http://www.libnavajo.org/
It looks to be extremely lightweight (< 20 classes) and perhaps something that could work. The documentation is unclear about some of your other specifications, but it's something to try perhaps.

How do I display HTML in a C++ Window that works on XP through Win8?

I'm looking for some simple code that will display HTML in a c++ window. I need it to be able to be run on any operating system (can't rely on .Net framework or Java or anything like that).
So far I've found this simple HTML drawing class: http://www.codeproject.com/Articles/3912/A-Simple-HTML-drawing-class
BUT, it doesn't support displaying images.
Does anyone know of some good code out there?
You should have a look at the Qt framework, it does everything you need: embedded WebKit view, cross-platform, network requests to fetch your HTML if needed...

Practice CSS and HTML without worrying about backend

I'm looking for a way to practice CSS and HTML without worrying about whether the backend works or not, or whether or not I have to make the content. I've played around with javascript and node.js a bit, and although I feel like I have a (very) rudimentary understanding of it, I feel as if I should be learning HTML and CSS correctly before messing more with the backend.
Is there a good place to just write CSS and HTML? How did you learn them?
Is there a code editor I should be using (specifically for HTML layouts and CSS layouts) besides Sublime Text?
Well, first of all, you do not worry about how backend works if what you want is to practice CSS and HTML.
Easy steps to play around with HTML and CSS:
create a new file, say index.html. Then, just double click on that file or open with.. your favorite browsers (Chrome, Safari, Opera, Mozilla, or IE).
If you want CSS, you can attach it to the index.html by using <link rel="stylesheet" href="file.css">.
Note : You would only need Node.js when you are dealing with AJAX method like using XMLHttpRequest or $.ajax() method due to CORS (Cross Domain Policy. Other than that, just play around with HTML and CSS with the browser.
My Personal Journey to the Front End Web Development
About me
I am currently working as a full time Front End Web Developer and I self-studied coding for 2 years now (I started this in June 2012) from almost zero knowledge about coding. When I started this, HTML5 and CSS3 were briefly introduced to the public so I learned HTML4 beforehand.
Web is fairly a big topic if we talk about the full stack integration (from the browser to the server to the database). If you are into the front end (HTML/CSS/Javascript), start off with some online tutorials (link below), then try to create your own web product (it could be a website or a web app). Try to improve a bit by a bit, and if you ever get stuck, you can always google search your problem and try to find the solution online (usually StackOverflow).
About Text Editor
I think the best way to learn is to get your hands dirty with minimal code help as possible. This will force you to remember most of the syntax and in turn increase your productivity. I was using Notepad++ but then switched to Sublime Text (Currently Sublime Text 3), and is my favorite text editor up until now. I know my co-worker is using emacs or vim that has a lot of keyboard shortcuts. Personally, Sublime Text is good enough to write HTML and CSS. Link: http://www.sublimetext.com/3
I started learning HTML and CSS from these links:
Paid
http://www.codeschool.com
Free
http://www.codeacademy.com
http://code.org
Hope it helps,
Yanuar Wibisono
Have you looked at w3schools html and CSS tutorials ?
They have a very handy "Try it yourself" button which allows you to try out your own code and see the results very quickly. The tutorials themselves are also well written with plenty of example code.
For HTML and CSS, I would recommend the text editor Microsoft WebMatrix, which is a standard program for Windows. For learning HTML and CSS, check out http://codeacademy.com. It's one of the best places to learn HTML, CSS and a bunch of other coding languages.

VB.NET: WYSIWYG page maker tutorial

I have a course work for which I have to make a (as advanced as possible) WYSIWYG web page editor in VB.NET (2010). It should have a visual editor with drag-drop support for several elements such as anchors, images, tables etc., and it should generate HTML based on that structure.
I don't know where to begin though.. I have some experience with vb.net, I made a tabbed notepad vaguely following a tutorial, but I don't know how to make this drag-drop thingy in a richtextbox.
I've searched for a tutorial, but most of them are just too simple - a text editor with browser control rendering the HTML.. I found one really nice and advanced, but it's in german :-|
So, if anyone knows any resources / tutorials I could use to start things I'll appreciate it.
I won't start with a richtextbox. Do you want to realize it in WPF or Forms (I would recommend WPF)?
In WPF there is relative simple a Drag-And-Drop behavior for elements (see http://msdn.microsoft.com/en-en/library/ms742859.aspx).
I would start with some simple elements (e.g. TextBoxes) and drag-drop them from some sort of toolbox onto a grid with fixed columns and rows (and later use a canvas). And then generate the HTML-Code from that.
In general, most of the WYSIWYG browser based editors are written in Javascript using an editable DIV.
A good example is tinymce:
http://www.tinymce.com/
Download, including full source code, is available here:
http://www.tinymce.com/download/download.php
You can use CKEditor. Its one of the best WYSIWYG editor i have worked with. Its highly customizable and opensource.
Given below is the URL for the website:
http://ckeditor.com/

Alternatives to HTML for website creation?

It seems the most common aproach to web design is to use HTML/XHTML & CSS in conjunction with other technologies or languages like Javascript or PHP.
On a theoretical level, I'm interested to know what other languages or technologies could be used to build an entire site without using a single HTML tag or CSS style for styling/positioning?
Could a website be made only using XML or PHP alone, including actual styling and positioning?
Presumably Flash sites are till embedded in HTML tags?
Thanks
There are actually several solutions that allow you to nearly completely avoid CSS and HTML.
GWT: Google Web Toolkit
Written in Java and will allow you to build both server and client code in Java. Used to build Google Wave.
Cappuccino and Objective-J:
Objective-J is to JavaScript as Objective-C is to C. It extends JavaScript with many near features, including type-checking, classes and types.
Cappuccino is like Cacoa (Mac OS X GUI toolkit).
Using these two you can build incredibly rich and desktop like webapps. They run mostly on the client side and you can use whatever you want on the server.
A good example is 280slides
SproutCore is similar to Cappuccino, but it uses pure JavaScript instead. Apple is using SproutCore to make me.com.
I should also mention that knowledge to HTML, CSS, JavaScript is a good skill to know, just like understanding your compiler is a good skill.
EDIT:
As said above Adobe Flash can also be used.
You can make a website with out a single html tag. Just give folder read access to all your directories, have sensible file names. From here you user will be able to browse images , read text files, download videos and depending on the content he may or may not come back ever again, but you do achieve the goal of setting up a "website" with out a single line of html or css or any other code for that matter.
:-) :-) :-)
You can host a telnet server with anonymous access and a specialized shell that restricts the user to doing whatever it is you want the site to do. ;)
Lets make the distinction between what is required by the web browser, and what you as a developer use to create that markup.
Remember that HTML nowadays is xml. You could use any markup language you like and convert that to HTML using XML.
eg ASP.NET uses markup such as which is converted on the server to .
As long as the content going down the wire to the browser is HTML, or generates HTML through script, you can use any approach you like.
However these approaches have mostly failed as developers prefer having direct control over the markup. It makes css as well as scripting much easier when you are certain what the html is going to be.
ASP.NET MVC is a product created in response to criticisms leveled at the ASP.NET webforms model.
Also, this is another answer because it's a completely different technology, but you can write an application in XUL and it'll run in Mozilla-based browsers without any HTML.
There's also XML. You can create websites with XML only. A well known one is World Of Warcraft. Check the page source. An XSL is used as stylesheet. There exist even XML based web frameworks like OpenLaszlo. You can let it serve either DHTML or Flash on reqeust out of a single XML template.
The Wt C++ Web Toolkit.
You can write your web application in C++ using Qt-style widgets (input boxes, buttons, tabs etc) and hook up client-side events to C++ code on your server. All without writing any HTML or CSS.
A sample application from their website (you may also want to look at this excellent tutorial):
HelloApplication::HelloApplication(const WEnvironment& env)
: WApplication(env)
{
setTitle("Hello world"); // application title
root()->addWidget(new WText("Your name, please ? ")); // show some text
nameEdit_ = new WLineEdit(root()); // allow text input
nameEdit_->setFocus(); // give focus
WPushButton *b = new WPushButton("Greet me.", root()); // create a button
b->setMargin(5, Left); // add 5 pixels margin
root()->addWidget(new WBreak()); // insert a line break
greeting_ = new WText(root()); // empty text
/* when the button is clicked, call the 'greet' method */
b->clicked().connect(this, &HelloApplication::greet);
}
void HelloApplication::greet()
{
/* set the empty text object greeting_ to greet the name entered */
greeting_->setText("Hello there, " + nameEdit_->text());
}
Curl (requires a browser plugin)
Wikipedia article
A webpage looks like this:
{curl 1.7 applet}
{value
let b:int=99
let song:VBox={VBox}
{while b > 0 do
{song.add b & " bottle(s) of beer on the wall,"}
{song.add b & " bottle(s) of beer."}
{song.add "Take one down, pass it around,"}
set b = b - 1
{song.add b & " bottle(s) of beer on the wall."}
}
song
}
Source
Since browsers view HTML, I'm assuming you mean create a site without ever having to edit/write HTML/CSS. The framework/app environment/whatever taking care of everything for you - yet still allowing you control over the presentation layer.
Seems like that is certainly possible on a theoretical level.
I ran across Noloh (not one line of html) a while back. Was intrigued, but never actually tried it out.
From various places on the Noloh site:
Because NOLOH does not rely on HTML or pages, maintaining complex rich Internet applications is significantly easier than with other methods.
Developing applications with NOLOH only requires using a single, unified language: a superset of PHP that completely maintains all aspects of server-client communication for you!
I think you could build a site entirely in SVG.
The front page of emacsformacosx is almost entirely SVG, for example.
Downsides: It wouldn't be viewable in IE (at least through version 8). And last I looked, text support, like flowing and justification, was weaker in SVG. (You could embed HTML inside an SVG element when you needed sophisticated text features, but that would violate your no-HTML rule.)
You'd probably still want to use CSS with SVG, because it's a good idea there for the same reason it's a good idea with HTML, but it wouldn't be necessary.
A website is always viewed through a browser (at least always if you are human :)). Browsers understand HTML. Whatever the technology - you have to basically render HTML. Even in cases with rich technologies like flash, the flash object that is rendered by a browser plugin is embedded inside the HTML.
In theory it is possible to do it without HTML, but the question becomes how much does the product diverge from the definition of a website...
One really short, simple answer... you can't :D
Flash requires an embed tag, an image requires an embed tag etc, so you'd have to use HTML in some method or another.
PHP is an embedded language, it is used to generate HTML on which the browsers renders, with XML, well technically a browser like Ie or FireFox will render it in it's own way for readability, but I would not class that as a website.
The major developments in the world of web technologies involves the development of HTML and CSS to improve them, there isn't any need for an alternative. In fact we're pushing towards a standard, what point would there be in introducing a new language to negate these standards. The whole IE saga would simply get worse.
Like the others have suggested, you could directly load an image or a flash file, but an image is useless on it's own, and a flash interface throws up loads of problems like SEO, accessibility etc, not least it's very heavy and usually completely misused. In my mind I wouldn't even class this method as a website, it just doesn't tick any of the boxes (IMO).
I think you can have an URL pointing directly at a hosted Flash (SWF) file, I've certainly done this though I don't know if all browsers work.
Anyhow, I tested this when developing MyDinos.
e.g: http://mydinos.com/home.swf
You can use Emscripten and its SDL subset.
You could try using quickstatic. You can code HTML templates from Python3. What is super cool about it is the fact that if you put in a for-loop for a certain item, you can generate that many items (maybe even use it to print items from a directory or quickly serve thousands of links).