Article View: borland.public.jbuilder.java.swing
Article #9999Re: Use of FormView
From: rofshi
Date: Thu, 09 Dec 1999 00:00
Date: Thu, 09 Dec 1999 00:00
116 lines
3913 bytes
3913 bytes
In article <80rd76$ifs14@forums.borland.com>,
"J. Leroy" <jjacques@net.em.com.br> wrote:
> Does anyone know how to use the FormView component that comes in the
package
> javax.swing.text.html?
> I'm trying to display a HTML page in a java application and the
JEditorPane
> is not working fine so I'm trying to use this component but I
couldn't find
> any documentation about it.
> Thanks,
>
> J. Leroy.
>
> forum: borland.public.jbuilder.java.swing
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.awt.*;
import java.awt.event.*;
public class SimpleFormViewDemo extends JPanel {
// a test HTML text
String ex = "<HTML> <HEAD> <TITLE>Contact Us</TITLE> </HEAD> " +
"<BODY BGCOLOR=\"white\" TEXT=\"black\" > " +
"<CENTER> <FONT SIZE=6><B>Contact Us</B></FONT>"+
" <P> </P></CENTER>"+
"<FORM ACTION=\"/session/sendmail\" METHOD=\"POST\">"+
"<INPUT TYPE=\"submit\" VALUE=\"Submit\">" +
"</FORM> </BODY></HTML>";
public SimpleFormViewDemo() {
super();
FVEditorKit fvKit = new FVEditorKit();
JEditorPane editorPane = new JEditorPane();
editorPane.setEditorKitForContentType("text/html", fvKit);
editorPane.setContentType("text/html");
editorPane.setBackground(Color.white);
editorPane.setEditable(false);
JScrollPane editorScrollPane = new JScrollPane();
editorScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
editorScrollPane.setPreferredSize(new Dimension(500, 300));
editorScrollPane.setMinimumSize(new Dimension(10, 10));
JViewport vp = editorScrollPane.getViewport();
vp.add(editorPane);
add(editorScrollPane);
editorPane.setText(ex);
}
public class FVEditorKit extends HTMLEditorKit {
public FVEditorKit() {
super();
}
public String getContentType() {
return "text/html";
}
public ViewFactory getViewFactory() {
return new FVFactory();
}
public class FVFactory extends HTMLFactory {
public View create(Element elem) {
Object obj = elem.getAttributes().
getAttribute(StyleConstants.NameAttribute);
if (obj instanceof HTML.Tag) {
HTML.Tag kind = (HTML.Tag) obj;
if ( kind == HTML.Tag.INPUT ) {
return new HTMLView(elem);
}
}
return super.create(elem);
}
}
class HTMLView extends FormView {
HTMLView(Element elem) {
super(elem);
}
// responds when the button is pressed
public void actionPerformed(ActionEvent ae) {
System.out.println("It is me!");
}
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new SimpleFormViewDemo());
frame.pack();
frame.setVisible(true);
}
}
Sent via Deja.com http://www.deja.com/
Before you buy.
Technical Details
Message-ID:
<82o2hi$rg5$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<80rd76$ifs14@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,f4c59043a5622d6f X-Google-Attributes: gid111d45,public From: rofshi@my-deja.com Subject: Re: Use of FormView Date: 1999/12/09 Message-ID: <82o2hi$rg5$1@nnrp1.deja.com> X-Deja-AN: 558359000 References: <80rd76$ifs14@forums.borland.com> X-Http-Proxy: 1.0 x43.deja.com:80 (Squid/1.1.22) for client 213.8.1.94 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Thu Dec 09 11:07:31 1999 GMT X-MyDeja-Info: XMYDJUIDrofshi Newsgroups: borland.public.jbuilder.java.swing X-Http-User-Agent: Mozilla/4.04 [en] (Win95; I)